- Home /
Overwrite the inspector window on Scene Asset heading chosen in the hierarchy window
I'm currently working on a project which uses many scenes to represent chunks of the game world. There are different types of scenes for different purposes, each having their own sets of prefabs which should be instantiated within those scenes. So I created a simple editor window which will will give a different set of objects to instantiate depending upon the active scene.
However, I don't want to always switch the active scene before I create the objects and it would be simpler if I could just use the inspector. My hierarchy window has a bunch of scene headings and all the objects they contain. I would like to choose one of these scene headings and have a list of game objects to instantiate in the scene in the inspector window.
It doesn't seem like the Scene headers in the hierarchy window actually are the scene assets (which might be a good thing). For one thing, I get a null object reference if I try to get the object from the instanceID given to me by reading the hierarchy window:
static void HierarchyWindowItemOnGUI (int instanceID, Rect selectionRect) {
GameObject gameObject = EditorUtility.InstanceIDToObject (instanceID) as GameObject;
}
Secondly, the inspector window when choosing a scene asset in the project window contains an open button but which doesn't exist for the scene asset when chosen in the hierarchy window. So obviously, it must not be the actual asset. Likewise, if I write a CustomEditor for SceneAssets, all the functionality only exists on the asset chosen in the project window and is greyed out.
Obviously there is some way to reference the scene heading since there's a number of drop down options when you right click and I can add to the list of GameObjects to be instantiated here. But how do I override the empty inspector on selection and put this functionality there?