Ejemplo n.º 1
0
        /// <summary>
        /// 展开或关闭Inspector中某类基类组件
        /// </summary>
        /// <param name="types">组件Editor的Type字符串列表</param>
        /// <param name="visible">是否展开</param>
        /// <param name="contraOther">是否将没有在types中的组件做相反的操作,传false保持不变</param>
        public static void SetInspectorTrackerVisible(string[] types, bool visible, bool contraOther = true)
        {
            var windowType = typeof(EditorWindow).Assembly.GetType(GetViewTypeStr(EditorViews.InspectorWindow));
            var window     = GetWindow(windowType);

            System.Reflection.FieldInfo info    = windowType.GetField("m_Tracker", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            ActiveEditorTracker         tracker = info.GetValue(window) as ActiveEditorTracker;
            var editors = tracker.activeEditors;

            for (int i = 0; i < editors.Length; i++)
            {
                bool isSame = false;
                foreach (var type in types)
                {
                    isSame = editors[i].GetType().ToString().Equals(type);
                    if (isSame)
                    {
                        tracker.SetVisible(i, isSame && visible ? 1 : 0);
                        break;
                    }
                }
                if (!isSame && contraOther)
                {
                    tracker.SetVisible(i, isSame && visible ? 1 : 0);
                }
            }
        }
Ejemplo n.º 2
0
        // Non-serialized expanding
        void SetVisible(bool visible)
        {
            var index = EditorElementRef.GetEditorIndex(editor.element);

            tracker.SetVisible(index, visible ? 1 : 0);
            editor.inspector.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
        }
Ejemplo n.º 3
0
    public static void FoldAll(MenuCommand command)
    {
        ActiveEditorTracker editorTracker = ActiveEditorTracker.sharedTracker;

        Editor[] editors = editorTracker.activeEditors;

        bool areAllFolded = true;

        for (int i = 1; i < editors.Length; i++)
        {
            int getVisible = editorTracker.GetVisible(i);

            Editor edit   = editors[i];
            string name   = edit.name;
            string target = edit.target.name;
            Type   type   = edit.target.GetType();

            if (editorTracker.GetVisible(i) != 0)
            {
                areAllFolded = false;
                break;
            }
        }

        for (int i = 1; i < editors.Length; i++)
        {
            editorTracker.SetVisible(i, areAllFolded ? 1 : 0);
        }
    }
        public static void FoldAll(MenuCommand command)
        {
            ActiveEditorTracker editorTracker = ActiveEditorTracker.sharedTracker;

            Editor[] editors = editorTracker.activeEditors;

            bool areAllFolded = true;

            for (int i = 1; i < editors.Length; i++)
            {
                if (editorTracker.GetVisible(i) > 0)
                {
                    areAllFolded = false;
                }
            }

            for (int i = 1; i < editors.Length; i++)
            {
                if (editorTracker.GetVisible(i) < 0)
                {
                    continue;
                }

                editorTracker.SetVisible(i, areAllFolded ? 1 : 0);
                InternalEditorUtility.SetIsInspectorExpanded(editors[i].target, areAllFolded);
            }
        }
Ejemplo n.º 5
0
    private static void CollapseComponents(MenuCommand command)
    {
        // Credit: https://forum.unity.com/threads/is-it-possible-to-fold-a-component-from-script-inspector-view.296333/#post-2353538
        ActiveEditorTracker tracker = ActiveEditorTracker.sharedTracker;

        for (int i = 0, length = tracker.activeEditors.Length; i < length; i++)
        {
            tracker.SetVisible(i, 0);
        }

        EditorWindow.focusedWindow.Repaint();
    }
    static void expand()
    {
        EditorApplication.ExecuteMenuItem("Window/General/Inspector");
        ActiveEditorTracker tracker = ActiveEditorTracker.sharedTracker;

        for (int i = 0, length = tracker.activeEditors.Length; i < length; i++)
        {
            tracker.SetVisible(i, 1);
            UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded(tracker.activeEditors[i].serializedObject.targetObject, true);
        }
        EditorWindow.focusedWindow.Repaint();
    }
    static void Shrinkage()
    {
        var                 type    = typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow");
        var                 window  = EditorWindow.GetWindow(type);
        FieldInfo           info    = type.GetField("m_Tracker", BindingFlags.NonPublic | BindingFlags.Instance);
        ActiveEditorTracker tracker = info.GetValue(window) as ActiveEditorTracker;

        for (int i = 0; i < tracker.activeEditors.Length; i++)
        {
            //这里1就是展开,0就是合起来
            tracker.SetVisible(i, 0);
        }
    }
Ejemplo n.º 8
0
    protected void OpenComponent(string name)
    {
        var                 type    = typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow");
        var                 window  = EditorWindow.GetWindow(type);
        FieldInfo           info    = type.GetField("m_Tracker", BindingFlags.NonPublic | BindingFlags.Instance);
        ActiveEditorTracker tracker = info.GetValue(window) as ActiveEditorTracker;

        for (int i = 0; i < tracker.activeEditors.Length; i++)
        {
            //可以通过名子单独判断组件展开或不展开
            if (tracker.activeEditors[i].target.GetType().Name == name)
            {
                //这里1就是展开,0就是合起来
                tracker.SetVisible(i, 1);
            }
        }
    }
    static void Expansion()
    {
        var                 type    = typeof(EditorWindow).Assembly.GetType("UnityEditor.InspectorWindow");
        var                 window  = EditorWindow.GetWindow(type);
        FieldInfo           info    = type.GetField("m_Tracker", BindingFlags.NonPublic | BindingFlags.Instance);
        ActiveEditorTracker tracker = info.GetValue(window) as ActiveEditorTracker;

        for (int i = 0; i < tracker.activeEditors.Length; i++)
        {
            ////可以通过名子单独判断组件展开或不展开
            //if (tracker.activeEditors[i].target.GetType().Name != "NewBehaviourScript")
            //{
            //这里1就是展开,0就是合起来
            tracker.SetVisible(i, 1);
            //}
        }
    }
Ejemplo n.º 10
0
        public static void FoldAll(MenuCommand command)
        {
            ActiveEditorTracker editorTracker = ActiveEditorTracker.sharedTracker;

            Editor[] editors = editorTracker.activeEditors;

            bool areAllFolded = true;

            for (int i = 1; i < editors.Length; i++)
            {
                if (editorTracker.GetVisible(i) != 0)
                {
                    areAllFolded = false;
                    break;
                }
            }

            for (int i = 1; i < editors.Length; i++)
            {
                editorTracker.SetVisible(i, areAllFolded ? 1 : 0);
            }
        }
Ejemplo n.º 11
0
        public void Show()
        {
            GameObject go = null;

            if (OpenNeededSceneIfNecessary(true))
            {
                go = GetGameObjectWithThisIssue();
            }
            if (go != null)
            {
                CSObjectTools.SelectGameObject(go, location);

                if (location == RecordLocation.Scene)
                {
                    EditorApplication.delayCall += () =>
                    {
                        EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(path, typeof(Object)));
                    };
                }
                else
                {
                    if (gameObjectPath.Split('/').Length > 2)
                    {
                        EditorApplication.delayCall += () =>
                        {
                            EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(path, typeof(Object)));
                        };
                    }
                }

                ActiveEditorTracker tracker = CSEditorTools.GetActiveEditorTrackerForSelectedObject();
                tracker.RebuildIfNecessary();

                Editor[] editors = tracker.activeEditors;

                long[] ids         = new long[editors.Length];
                bool   targetFound = false;

                for (int i = 0; i < editors.Length; i++)
                {
                    Editor editor = editors[i];
                    long   id     = CSObjectTools.GetLocalIdentifierInFileForObject(editor.serializedObject.targetObject);
                    ids[i] = id;

                    if (id == componentId)
                    {
                        targetFound = true;

                        /* known corner cases when editor can't be set to visible via tracker */

                        if (editor.serializedObject.targetObject is ParticleSystemRenderer)
                        {
                            ParticleSystemRenderer renderer = (ParticleSystemRenderer)editor.serializedObject.targetObject;
                            ParticleSystem         ps       = renderer.GetComponent <ParticleSystem>();
                            componentId = CSObjectTools.GetLocalIdentifierInFileForObject(ps);
                        }
                    }
                }

                if (targetFound)
                {
                    for (int i = 0; i < editors.Length; i++)
                    {
                        tracker.SetVisible(i, ids[i] != componentId ? 0 : 1);
                    }
                }
            }
            else
            {
                MaintainerWindow.ShowNotification("Couldn't find object " + gameObjectPath);
            }
        }