I'm developing a class that can draw the interface both in the game and in the editor. Now I manually specify which mode to work. Because some functions are not available in different modes
class MyWindow : MonoBehaviour {
void OnGUI() {
myClass.OnGUI(GUIMode.Screen);
}
}
class MyEditorWindow : EditorWindow {
void OnGUI() {
myClass.OnGUI(GUIMode.Inspector);
}
}
I would like to learn how to detect this automatically. Is it possible?
What have already I tried: Google. Read documentation. Read Unity GUI-classes source code
There are scripting symbols you can use to conditionally compile things.
They can also be used to determine specific configurations of the environment, and set variables.
eg.
For specifically checking if you are in the editor, you can use the flag isEditor from the Application class.
There are more flags in the Application class to determine common environment context, such as
isMobilePlatform,isConsolePlatform,platform, etc.