Exemple #1
0
        public static void TraverseGameObjectComponents(ObjectTraverseInfo traverseInfo, ComponentTraverseCallback callback)
        {
            var components = traverseInfo.current.GetComponents <Component>();
            var checkingPrefabInstanceObject  = false;
            var checkingAddedToInstanceObject = false;

            if (traverseInfo.SkipCleanPrefabInstances)
            {
                checkingPrefabInstanceObject = traverseInfo.inPrefabInstance && !traverseInfo.inMissingPrefabInstance;
                if (checkingPrefabInstanceObject)
                {
                    checkingAddedToInstanceObject = PrefabUtility.IsAddedGameObjectOverride(traverseInfo.current);
                }
            }

            var hasDirtyComponents = traverseInfo.dirtyComponents != null;

            var visibleIndex = -1;

            for (var i = 0; i < components.Length; i++)
            {
                var component = components[i];
                if (CSComponentTools.IsComponentVisibleInInspector(component))
                {
                    visibleIndex++;
                }

                if (component == null)
                {
                    // to register missing script
                    callback(traverseInfo, null, visibleIndex);
                    continue;
                }

                // transforms are checked at the GameObject level
                if (component is Transform)
                {
                    continue;
                }

                if (!checkingPrefabInstanceObject)
                {
                    Stats.componentsTraversed++;
                    callback(traverseInfo, component, visibleIndex);
                }
                else
                {
                    var hasOverridenProperties = checkingAddedToInstanceObject;
                    if (!hasOverridenProperties && hasDirtyComponents)
                    {
                        if (Array.IndexOf(traverseInfo.dirtyComponents, component.GetInstanceID()) != -1)
                        {
                            hasOverridenProperties = true;
                        }
                    }

                    if (hasOverridenProperties)
                    {
                        Stats.componentsTraversed++;
                        callback(traverseInfo, component, visibleIndex);
                    }
                }
            }
        }
        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 = CSComponentTools.GetComponentIndex(ps);
                        }

                        break;
                    }
                }

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

                for (var i = 1; i < editors.Length; i++)
                {
                    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);
        }