- Home /
Is there an event to catch on Open a scene
Hey guys, I am searching for a possibility to automatically add some things like skybox etc. if i create a new scene or open a scene. This is part of a little Plugin. This Plugin has a menu directly in the Scene View. After Creating a new Scene there should be a skybox and a little menu. I am trying to realize that in this way:
[InitializeOnLoad]
[ExecuteInEditMode]
public class SceneGUI : ScriptableObject
{
static public Dictionary<string, SceneStrategy> strategy = new Dictionary<string, SceneStrategy>();
static public SceneStrategy current;
static bool minInspector;
static bool minBar;
static bool maxBar;
static Rect bar;
static Rect buttonBar;
static Rect inspector;
static Rect closeButton;
static Rect closeInspectorButton;
static Rect maxButton;
static GUIStyle barStyle;
static GUIStyle buttonBarStyle;
static GUIStyle inspectorStyle;
static Vector2 scrollBar;
static Vector2 scrollInsp;
static public GameObject groundTerrain;
static public GameObject mCamera;
static Material skybox;
public static void Awake()
{
}
public static void OnEnable()
{
Debug.Log("SceneGUI started");
//Create skybox etc
}
}
But this Debug Message (SceneGUI started) is not shown on startup or even if i create a new scene or open a scene.
I am calling this in the following Autorun.cs file:
[InitializeOnLoad]
public class Autorun
{
static Autorun()
{
Debug.Log("Start");
SceneGUI.OnEnable();
}
}
And This Debug message although isnt shown.
All this things are only shown if i edit my code, save it and go back to Unity...
Any idea what is wrong?
Hi,
$$anonymous$$aybe this document can help: http://docs.unity3d.com/Documentation/$$anonymous$$anual/RunningEditorCodeOnLaunch.html (and I think what's wrong in your code is that OnEnable cannot be "static") EDIT: OnEnable is not static for a $$anonymous$$onoBehavior, not in your case :). And your code is already the same as the document...
I need to compile the code manually or something like that. If went back to unity after editing my code and saving this, then it works fine.
$$anonymous$$aybe that helps: http://answers.unity3d.com/questions/574425/how-to-create-editorwindow-on-game-load.html
[ExecuteInEdit$$anonymous$$ode]
and
OnLevelWasLoaded() on an hidden, don't destroy on load object?