Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by amir_barak · Oct 02, 2014 at 12:36 PM · inspector

Query whether inspector is folded?

Hey, is there any way to query whether a custom editor (I call 'em inspectors) is collapsed/folded in the Unity editor via code?

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Oct 02, 2014 at 12:53 PM

I'm sure InternalEditorUtility.GetIsInspectorExpanded(target); is what you need. However Unity (or to be more precise the InspectorWindow) seperately tracks the visible state for each editor. The method i mentioned has to be passed the reference to the inspected object (editor.target).

If that doesn't work it's getting tricky since the InspectorWindow uses a seperate Tracker class to remember the visibility state on a per-index-base of the current editor array. With reflection almost everything is possible, but it quickly get very complex.

edit

Well, i just wrote a little helper class that simplifies the access to the internal class InspectorWindow:

 using UnityEditor;
 using System.Runtime.InteropServices;
 
 public static class InspectorWindowHelper
 {
     private static System.Type m_InspectorWindowType = null;
     private static _MethodInfo m_GetAllInspectors = null;
     private static _MethodInfo m_GetTracker = null;
     static InspectorWindowHelper()
     {
         foreach(var T in typeof(EditorApplication).Assembly.GetTypes())
         {
             if (T.Name == "InspectorWindow")
             {
                 m_InspectorWindowType = T;
                 m_GetAllInspectors = T.GetMethod("GetAllInspectorWindows",System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                 m_GetTracker = T.GetMethod("GetTracker",System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                 break;
             }
         }
     }
     
     public static EditorWindow[] GetAllInspectorWindows()
     {
         var array = m_GetAllInspectors.Invoke(null,null) as EditorWindow[];
         return array;
     }
     
     public static ActiveEditorTracker GetTracker(EditorWindow aWin)
     {
         var tracker = m_GetTracker.Invoke(aWin,null) as ActiveEditorTracker;
         return tracker;
     }
     
     public static void EnforceExpanded(System.Type aCustomEditor)
     {
         var windows = GetAllInspectorWindows();
         for(int n = 0; n < windows.Length; n++)
         {
             var tracker = GetTracker(windows[n]);
             var editors = tracker.activeEditors;
             for(int i = 0; i < editors.Length; i++)
             {
                 if (editors[i].GetType() == aCustomEditor)
                 {
                     int visible = tracker.GetVisible(i);
                     if (visible == 0)
                     {
                         tracker.SetVisible(i,1);
                     }
                 }
             }
         }
     }
 }

I've added an example method (EnforceExpanded) to show what you can do with it and how to use it.

EnforceExpanded can simply be called within OnInspectorGUI() of your custom inspector. Just pass the type of your editor class to prevent collapsing in all inspector windows.

You didn't say for what purpose you want that information and where you need it, so for the future you should be more precise when asking questions here.

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 amir_barak · Oct 02, 2014 at 03:50 PM 0
Share

Yeah, tried that but didn't work.

I haven't managed to reflect the particular tracker because I'm not sure where to get the InspectorWindow instance it belongs to from. Is there any sort of event I can hook into to get the state change at least that you know of?

avatar image Bunny83 · Oct 03, 2014 at 01:46 AM 0
Share

@amir-barak: I've updated my answer.

It would be great to get some feedback ;)

avatar image amir_barak · Oct 05, 2014 at 07:34 AM 0
Share

Haven't had a chance to test this out yet. Will post an update once I do.

avatar image amir_barak · Oct 06, 2014 at 01:57 PM 0
Share

Awesome. I'll post up my code a bit later (modified it to suit my needs but yeah, that's a good base to start working from). I still don't see why the visible flag is hidden.. The UnityEditor.Editor class should have an event fired when the visibility changes.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How does one inspect static vars? 3 Answers

Editor: multiple Inspectors 3 Answers

Getting the selected enum value set in the Inspector 2 Answers

WrapMode not visible in inspector 1 Answer

Singleton & Inspector 1 Answer


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