Create a Component Script for Editor Only

Hi guys, I’m working on some editor stuff right now.

so, I’m trying to create a component script that can be attached to any game objects in a scene, but this component are just for managing editor stuff, so when I’m build my game, this script will not included in my game.

how I do that? trying to tag the Game Object to EditorOnly just make the whole script including game object not included in build, also trying to move my component script to Editor folder just make it disappear from add component menu.

You could try using directives. For instance Application.Quit() did not work for Unity Editor so I added code inside a directive that did work in Unity Editor

Application.Quit();
#if UNITY_EDITOR
    UnityEditor.EditorApplication.isPlaying=false;
#endif