Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by zxj001 · Sep 01, 2016 at 06:02 AM · guieditor-scriptingeditorwindoweditorguieditor window

How do I get a reference to the default editor windows (Hierarchy, Console, and Inspector)?

I want to be able to get references to the default editor windows (inspector, hierarchy, console etc...) So that i can close, open and focus my own windows using them.

e.g. I want to do something like:

HierarchyWindow myWindow = (HierarchyWindow) EditorWindow.GetWindow();

thanks!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nj4242 · Sep 02, 2016 at 01:11 PM 0
Share

I Don't think there is any possibility, However some of the Windows functionality can be referenced, But I am not sure if you can code to open/close Inspector from the script. Think about it, its only silly, when you can adjust those windows easily with more functionality rather than open/close, so why code it. Its like coding the Unity. Its funny when Unity says I'll let you code, and here we are discussing let's code unity, Bruv!! Still its only my experience, what not can be possible right, Say I am optimistic! But, yeah, You might wanna ask in the moderators forum, If you're that serious.

Cheers!

avatar image nj4242 · Sep 09, 2016 at 05:12 AM 0
Share

Hey, I think this might help you : http://answers.unity3d.com/questions/303785/how-can-i-create-a-component.html

1 Reply

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Bunny83 · Sep 09, 2016 at 06:08 AM

Most built-in editor windows are internal classes, so you don't have direct access to those classes. You can use reflection if you want to access certain properties / fieldss / methods of those windows.

The only way to access them in the first place is by using reflection to get a System.Type reference of the desired class. This can be aquired by using the GetTypes method of the Assembly class of the UnityEditor assembly.

 public static System.Type[] GetAllEditorWindowTypes()
 {
     var result = new System.Collections.Generic.List<System.Type>();
     System.Reflection.Assembly[] AS = System.AppDomain.CurrentDomain.GetAssemblies();
     System.Type editorWindow = typeof(EditorWindow);
     foreach (var A in AS)
     {
         System.Type[] types = A.GetTypes();
         foreach (var T in types)
         {
             if (T.IsSubclassOf(editorWindow))
                 result.Add(T);
         }
     }
     return result.ToArray();
 }

This method will return all editor window types it can find in any loaded assembly (so even your own). Those types can be used with GetWindow or FindObjectsOfTypeAll to open / find a certain editorwindow

Though if you just want to find all open EditorWindows you can directly use Resources.FindObjectsOfTypeAll:

 EditorWindow[] allWindows = Resources.FindObjectsOfTypeAll<EditorWindow>();

Now you just have to filter out the ones you need based either on the type name ( win.GetType().Name ) or on the window title ( win.titleContent.text ).


However!

I don't think this would make any sense.

First of all there is nothing like a "default editor window". The user can decide which windows he wants to use and how many. You can open 3 scene views, 2 inspectors and no console at all. So trying to "access" the console window when it's not open will fail. Also having multiple windows of a certain type would need special handling.

Next thing is you can't "close" a window without destroying the window instance. So all current settings of that window will be reset when you re-open it. Closing a window has the same effect as clicking the little "x" at the top right of the window / tab. You can't "hide" a window.

Next thing is when you close a window that is currently docked you will rip the layout apart. Currently Unity doesn't provide a nice way to build up the layout from code. All required classes for this are internal (View, GUIView, HostView, DockArea, SplitView, MainWindow, ContainerWindow, ....).

And finally the most important point: Most users wouldn't use any tool that decides how their layout should look like or that closes other windows when it thinks it's required. Personally i work with a two monitor setup and i often have the gameview and some other windows on the second monitor. Other people may have more than two monitors and spread their windows across them. Closing / opening / moving / docking arbitrary windows automatically doesn't make any sense for any kind of tool unless it's a "window management tool"

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image skauth · Jun 23, 2017 at 06:55 PM 0
Share

This is extremely useful. Thank you for answering the question, even if you don't think it's useful.

I'm working on a simple FPS. When the player presses escape, my code does stuff like freezing the world, bringing up the GUI, etc. I have a #if UNITY_EDITOR... #endifthing in there for extra stuff to do. For example the Quit button makes the editor game stop playing. When I press go to a menu, I want to make the game window $$anonymous$$imize, so I can do stuff like enable/disable the ceiling and check error logs, such as why is this object not referenced?

I know I'm spending a long-ass time trying to figure out how to save myself two button clicks. But it shouldn't take a long-ass time to accomplish. So thank you for giving this answer.

avatar image skauth · Jun 23, 2017 at 07:04 PM 1
Share

To clarify: EditorWindow[] allWindows = Resources.FindObjectsOfTypeAll<EditorWindow>(); and filtering is what I found useful.

avatar image usernameHed · Apr 05, 2019 at 09:21 PM 0
Share

Hello, if I do System.Type[] allUnityWindow = GetAllEditorWindowTypes();with your custom function, how can I get the reference as EditorWindow ?

$$anonymous$$y Goad is to Open or focus an Animation window in the inspector. I have managed to find the animation window if it exist, and focus it. But if it doesn't exist, I would like to Create it / open it...

 EditorWindow[] allWindows = Resources.FindObjectsOfTypeAll<EditorWindow>();
             bool isOpen = false;
             for (int i = 0; i < allWindows.Length; i++)
             {
                 Debug.Log(allWindows[i].titleContent.text);
                 if (string.Equals(allWindows[i].titleContent.text, "Animation"))
                 {
                     allWindows[i].Focus();
                     isOpen = true;
                 }
             }
             if (!isOpen)
             {
                 Debug.Log("create window !");
                 System.Type[] allUnityWindow = UtilityEditor.GetAllEditorWindowTypes();
                 for (int i = 0; i < allUnityWindow.Length; i++)
                 {
                     //here How can I test for Animation window, and Create one ?
                 }
             }



avatar image Bunny83 usernameHed · Apr 06, 2019 at 12:35 AM -1
Share

Any EditorWindow can be opened with EditorWindow.GetWindow. Of course when you use a System.Type value you can't use the generic version since the generic version requires an actual type, not a System.Type instance.

Just read my answer carefully. The last sentence before the big "However" gave you the information / hint you need. As i said, the actual classnames of the built-in editor windoes are internal classes. So Unity could change them at any time since they are not documented nor part of the API they provide to us users.


Please, next time when you have a question or if something isn't clear, ask your own question ins$$anonymous$$d of hijacking someone else's question. The format of a Q&A site is simple. One question at the top, answers follows.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Text in custom editor is displayed/rendered with boxes around characters... 2 Answers

Editor GUI Foldout header style customization 0 Answers

Is it possible to store and display EditorGUILayout.Toggles? 0 Answers

How to get EditorWindow client rect? 1 Answer

Does Unity IMGUI for Editor use DirectX on Windows? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges