예제 #1
0
        protected GameObjectIssueRecord(RecordType type, RecordLocation location, string path, GameObject gameObject, Component component, Type componentType, string componentName) : this(type, location, path, gameObject)
        {
            this.componentName = componentName;

            componentId = CSObjectTools.GetLocalIdentifierInFileForObject(component);
            if (componentId > 0 && gameObject.GetComponents(componentType).Length > 1)
            {
                this.componentName += " (ID: " + componentId + ")";
            }
        }
        protected GameObjectIssueRecord(RecordType type, RecordLocation location, string path, GameObject gameObject) : base(type, location)
        {
            this.path      = path;
            gameObjectPath = CSEditorTools.GetFullTransformPath(gameObject.transform);
            objectId       = CSObjectTools.GetLocalIdentifierInFileForObject(gameObject);

#if UNITY_5_3_PLUS
            if (location == RecordLocation.Scene)
            {
                this.path = gameObject.scene.path;
            }
#endif
        }
예제 #3
0
        private Component GetComponentWithThisIssue(GameObject go)
        {
            Component component = null;

            Component[] components = go.GetComponents <Component>();
            for (int i = 0; i < components.Length; i++)
            {
                if (CSObjectTools.GetLocalIdentifierInFileForObject(components[i]) == componentId)
                {
                    component = components[i];
                    break;
                }
            }

            return(component);
        }
        protected GameObjectIssueRecord(RecordType type, RecordLocation location, string path, GameObject gameObject, Component component, Type componentType, string componentName) : this(type, location, path, gameObject)
        {
            if (component == null)
            {
                return;
            }

            this.component = componentName;
            if (gameObject.GetComponents(componentType).Length > 1)
            {
                long id = CSObjectTools.GetLocalIdentifierInFileForObject(component);
                if (id != 0)
                {
                    this.component += " (ID: " + id + ")";
                }
            }
        }
        private GameObject FindObjectInCollection(IEnumerable <GameObject> allObjects)
        {
            GameObject candidate = null;

            foreach (GameObject gameObject in allObjects)
            {
                if (CSEditorTools.GetFullTransformPath(gameObject.transform) != gameObjectPath)
                {
                    continue;
                }

                candidate = gameObject;
                if (objectId == CSObjectTools.GetLocalIdentifierInFileForObject(candidate))
                {
                    break;
                }
            }
            return(candidate);
        }
예제 #6
0
        // ----------------------------------------------------------------------------
        // fix missing component
        // ----------------------------------------------------------------------------

        private static void FixMissingComponents(GameObjectIssueRecord issue, GameObject go)
        {
            CSObjectTools.SelectGameObject(go, issue.location);

            ActiveEditorTracker tracker = CSEditorTools.GetActiveEditorTrackerForSelectedObject();

            tracker.RebuildIfNecessary();

            bool touched = false;

            Editor[] activeEditors = tracker.activeEditors;
            for (int i = activeEditors.Length - 1; i >= 0; i--)
            {
                Editor editor = activeEditors[i];
                if (CSObjectTools.GetLocalIdentifierInFileForObject(editor.serializedObject.targetObject) == issue.componentId)
                {
                    Object.DestroyImmediate(editor.target, true);
                    touched = true;
                }
            }

            if (touched)
            {
#if UNITY_5_0_PLUS
                if (issue.location == RecordLocation.Scene)
                {
                    CSSceneTools.MarkSceneDirty();
                }
                else
                {
                    EditorUtility.SetDirty(go);
                }
#else
                EditorUtility.SetDirty(go);
#endif
            }

            //CSObjectTools.SelectGameObject(null, issue.location);
        }
예제 #7
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);
            }
        }