- Home /
Call inspector on custom window editor
Hi there, here is the thing: in my scene i have several objects and each one of them have like 5 or 6 script components, and each one has several config options. So for organization's sake i decided to make a custom window that shows a node-like view of your selected gameobject, and it displays in a 2d view all the components that conform that game object ( and how they interact with each other, with arrows). When you select one component in that 2d view, a second inspector windows comes in showing you only the component that you selected so you can modify their options.
The problem is how to represent that inspector-like window, i've been searching alot but with no result. And on top of this, some scripts have a custom inspector script so that's why i'm trying to call an inspector window here. Does anyone know if this kind of thing is possible ? otherwise i would like to know if there is a better or different solution to this organization thing. Of course its not critical, but would help alot having one of this. Cheers
Answer by MaxEden · Sep 10, 2015 at 04:12 PM
Editor editor = Editor.CreateEditor( gameObject );
editor.DrawDefaultInspector();
I don't know how to draw it in specified area, but it works for plain drawing inside EditorWindow and even inside custom layout areas.
to draw it in specified area, use this:
Rect myRect = new Rect();
myRect.center = Vector2.one*200;
GUILayout.BeginArea(myRect);
myEditor.DrawDefaultInspector(); //confines the editor to the specified rectangle
GUILayout.EndArea();
Answer by Loius · Mar 30, 2013 at 05:22 AM
There's not really a way to call an inspector, unfortunately. You'd have to provide a function for each component, even the ones you'd rather have default inspector on.
If you're wondering about creating an actual editor window, you can use EditorWindow to do that.
yes that's actually what im doing, inside that editor window i was trying to display that 2d space with the little nodes representing the components of the object. it's such a shame that you don't have a little more freedom for controlling the inspector. Btw do you know a way for at least "call" the inspector window and dock it to the new custom window you just created ? (when using EditorWindow.GetWindow(typeof(WindowToDock));
I don't see an 'auto-dock' option, though what I did for a similar little excursion was I created my main Window in two Vertical layouts, and called th GUI function of the edited object in the second panel:
var editedObject : $$anonymous$$yEditableBaseClass;
function OnWindowGUI() {
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
// $$anonymous$$ain window GUI goes here, picks editedObject from its components
GUILayout.EndVertical();
GUILayout.Label(/*line texture*/);
GUILayout.BeginVertical();
editedObject.ShowEditorGUI();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
There's also EditorWindow.ShowAuxWindow; I've never used that myself but it sounds like maybe a thing you'd be interested in trying.
well thanks! that helps alot in the distribution window thing. now there only remains the inspector window problem. I'm thinking i could create ( not very happy with this tho ) a new gameobject in the scene or as an asset, extract from the original object the component i wish to inspect, and paste it in the new temporal object. Then i could give focus to that object to show up in the inspector, and after finishing changes i could copy back that component to the original object. the thing im not happy with is creating a whole new game object with will have the transform component, so im still thinking and searching for another ways. Thanks for your comment !
Answer by LaireonGames · Dec 03, 2018 at 12:41 PM
Based upon @MaxEden 's answer this is how to do it with a custom inspector rather than the Unity default one:
AchievementEditor editor = (AchievementEditor)Editor.CreateEditor(achievement.objectReferenceValue, typeof(AchievementEditor));
editor.OnInspectorGUI();
Where AchievementEditor is the name of my custom editor.
Answer by CaJerry87 · Jul 05, 2020 at 09:52 PM
This is more of a conceptual suggestion but what if you just added a new inspector tab and then saved the layout? Let unity remember that you want to have an inspector there(instead of hard coding it). Also, look into Bolt. It's a node-based programming asset purchased and released by Unity. It costs a pretty penny but I think its right up your alley and would let you get deeper into your projects.