I know there is an attribute to make a script execute in editor, but, how can i do to, cleanly, make the script execute just when in editor mode and not while running the game?
2 Answers
2Nevermind, found it!
I just used:
if(!Application.isPlaying)
{
// code here for Editor only
}
Use #if UNITY_EDITOR //Code here for Editor only. #endif [http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html][1] [1]: http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html
– meat5000Is this used in conjunction with [ExecuteInEditMode] ?
– JChiltonFrom the looks of what you're doing, it would be better if you made an EditorWindow... Not only from a design perspective, but as a sanity check. If you leave your project for a while, then come back you will be utterly puzzled why some stuff is only running in the Editor.
– JamoraThought of thta, but decided not, because the wditor window wouldn't have anything... but maybe you're right. Anyway i think that works for now.
– HendrysTobarThis solution add a small overhead into your runtime code. If it's only executed once, you're probably fine, other way, meat 5000 solution is better as it isolates your code to the Editor side. If you want to execute something at editor only (not in runtime), you should put your code into a folder called "Editor". There, you can use [ExecuteInEditMode] or [InitializeOnLoadMethod] depending of what you wanna do. You can see more about that [here][1]. [1]: http://yvesalbuquerque.wix.com/ygamedev#!Unity-EditorSide-Part-I-Inspector/cai5/55c61e4b0cf2e442d27cbf4e
– YJack