コード例 #1
0
        public static bool TryFoldAllComponentsExceptId(long componentId)
        {
            var tracker = CSEditorTools.GetActiveEditorTrackerForSelectedObject();

            if (tracker == null)
            {
                Debug.LogError(Maintainer.ConstructError("Can't get active tracker."));
                return(false);
            }

            tracker.RebuildIfNecessary();

            var editors = tracker.activeEditors;

            if (editors.Length > 1)
            {
                var targetFound = false;
                var skipCount   = 0;

                for (var i = 0; i < editors.Length; i++)
                {
                    var editor           = editors[i];
                    var editorTargetType = editor.target.GetType();
                    if (editorTargetType == CSReflectionTools.assetImporterType ||
                        editorTargetType == CSReflectionTools.gameObjectType)
                    {
                        skipCount++;
                        continue;
                    }

                    if (i - skipCount == componentId)
                    {
                        targetFound = true;

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

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

                        break;
                    }
                }

                if (!targetFound)
                {
                    return(false);
                }

#if UNITY_2018_3_OR_NEWER
                for (var i = 1; i < editors.Length; i++)
#else
                for (var i = 0; i < editors.Length; i++)
#endif
                {
                    tracker.SetVisible(i, i - skipCount != componentId ? 0 : 1);
                }

                var inspectorWindow2 = CSEditorTools.GetInspectorWindow();
                if (inspectorWindow2 != null)
                {
                    inspectorWindow2.Repaint();
                }

                // workaround for bug when tracker selection gets reset after scene open
                // (e.g. revealing TMP component in new scene)
                EditorApplication.delayCall += () =>
                {
                    EditorApplication.delayCall += () =>
                    {
                        try
                        {
                            for (var i = 0; i < editors.Length; i++)
                            {
                                tracker.SetVisible(i, i - skipCount != componentId ? 0 : 1);
                            }

                            var inspectorWindow = CSEditorTools.GetInspectorWindow();
                            if (inspectorWindow != null)
                            {
                                inspectorWindow.Repaint();
                            }
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    };
                };
            }

            return(true);
        }
コード例 #2
0
ファイル: CSObjectTools.cs プロジェクト: s1gurd/W-Hub
 public static string GetNicePropertyPath(string fullPropertyPath)
 {
     return(CSEditorTools.NicifyName(RemoveArrayStuffFromProperty(fullPropertyPath)));
 }