Example #1
0
        protected override void ConstructBody(StringBuilder text)
        {
            text.Append(Location == RecordLocation.Scene ? "<b>Scene:</b> " : "<b>Prefab:</b> ");

            var nicePath = CSPathTools.NicifyAssetPath(Path, true);

            text.Append(nicePath);

            if (!string.IsNullOrEmpty(transformPath))
            {
                text.Append("\n<b>Object:</b> ").Append(transformPath);
            }
            if (!string.IsNullOrEmpty(componentName))
            {
                text.Append("\n<b>Component:</b> ").Append(componentName);
            }
            if (!string.IsNullOrEmpty(componentNamePostfix))
            {
                text.Append(componentNamePostfix);
            }
            if (!string.IsNullOrEmpty(propertyPath))
            {
                var propertyName = CSObjectTools.GetNicePropertyPath(propertyPath);
                text.Append("\n<b>Property:</b> ").Append(propertyName);
            }
        }
Example #2
0
 protected override void ConstructBody(StringBuilder text)
 {
     text.Append("<b>Settings: </b>" + SettingsKind);
     if (!string.IsNullOrEmpty(PropertyPath))
     {
         var propertyName = CSObjectTools.GetNicePropertyPath(PropertyPath);
         text.Append("\n<b>Property:</b> ").Append(propertyName);
     }
 }
Example #3
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 + ")";
            }
        }
Example #4
0
        protected GameObjectIssueRecord(IssueKind kind, RecordLocation location, string path, GameObject gameObject) : base(kind, location, path)
        {
            var transform = gameObject.transform;

            transformPath = CSEditorTools.GetFullTransformPath(transform);

            if (kind != IssueKind.MissingPrefab)
            {
                objectId = CSObjectTools.GetUniqueObjectId(gameObject);
            }
        }
Example #5
0
        private static bool LookForObjectsReferencesInHierarchy(Object[] objects, List <HierarchyReferenceItem> results)
        {
            var foundReferences   = new Dictionary <int, Dictionary <ExactReferenceData, List <ExactReferenceData> > >(objects.Length);
            var objectInstanceIds = CSObjectTools.GetObjectsInstanceIDs(objects);

            var canceled = HierarchyEntryFinder.FillHierarchyReferenceEntries(objects, (lookAt, lookForInstanceId, settings) =>
            {
                for (var i = 0; i < objectInstanceIds.Length; i++)
                {
                    var instanceId = objectInstanceIds[i];
                    if (instanceId == lookForInstanceId)
                    {
                        ExactReferenceData referenced;

                        if (!foundReferences.ContainsKey(instanceId))
                        {
                            foundReferences.Add(instanceId, new Dictionary <ExactReferenceData, List <ExactReferenceData> >());
                            referenced = ObjectToReferencingEntry(objects[i]);
                            foundReferences[instanceId].Add(referenced, new List <ExactReferenceData>());
                        }
                        else
                        {
                            referenced = foundReferences[instanceId].Keys.First();
                        }

                        var assetPath = CSObjectTools.TryGetObjectAssetPath(lookAt);
                        var reference = EntryGenerator.CreateNewReferenceEntry(EntryFinder.currentLocation, lookAt,
                                                                               lookAt as GameObject, settings);

                        var referenceData = new ExactReferenceData
                        {
                            assetPath = assetPath,
                            reference = reference
                        };

                        foundReferences[instanceId][referenced].Add(referenceData);
                    }
                }
            });

            if (!canceled && foundReferences.Count > 0)
            {
                BuildTree(foundReferences, results);
            }

            if (canceled)
            {
                HierarchyReferencesTab.AutoSelectHierarchyReference = null;
            }

            return(canceled);
        }
        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
        }
        protected override void ConstructBody(StringBuilder text)
        {
            text.Append("<b>Scriptable Object:</b> ");
            text.Append(CSPathTools.NicifyAssetPath(Path, true));

            if (!string.IsNullOrEmpty(typeName))
            {
                text.Append("\n<b>Type:</b>").Append(typeName);
            }

            if (!string.IsNullOrEmpty(propertyPath))
            {
                var propertyName = CSObjectTools.GetNicePropertyPath(propertyPath);
                text.Append("\n<b>Property:</b> ").Append(propertyName);
            }
        }
Example #8
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);
        }
Example #11
0
        protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
        {
            var objectReferences = DragAndDrop.objectReferences;

            if (objectReferences == null || objectReferences.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            for (var i = 0; i < objectReferences.Length; i++)
            {
                var monoBehaviour = objectReferences[i] as MonoBehaviour;
                if (monoBehaviour == null)
                {
                    continue;
                }

                var monoScript = MonoScript.FromMonoBehaviour(monoBehaviour);
                if (monoScript == null)
                {
                    continue;
                }

                objectReferences[i] = monoScript;
            }

            var ids         = CSObjectTools.GetObjectsInstanceIDs(objectReferences);
            var assetsPaths = ProjectScopeReferencesFinder.GetAssetsFromInstances(ids);

            if (assetsPaths.Length == 0)
            {
                return(DragAndDropVisualMode.Rejected);
            }

            if (Event.current.type == EventType.DragPerform)
            {
                EditorApplication.delayCall += () => { ReferencesFinder.FindAssetsReferences(assetsPaths.ToArray()); };
                DragAndDrop.AcceptDrag();
            }

            return(DragAndDropVisualMode.Generic);
        }
Example #12
0
		private static void OnGameObjectComponentTraverse(ObjectTraverseInfo traverseInfo, Component component, int orderIndex)
		{
			if (component == null) return;

			var target = traverseInfo.current;
			var componentName = CSComponentTools.GetComponentName(component);
			if (CSObjectTools.IsHiddenInInspector(component))
			{
				orderIndex = -1;
			}

			var addSettings = new EntryAddSettings
			{
				componentName = componentName,
				componentIndex = orderIndex,
				componentInstanceId = component.GetInstanceID(),
			};

			TraverseObjectProperties(target, component, addSettings);
		}
Example #13
0
        private Object GetObjectWithThisIssue()
        {
            Object result = null;

            if (Location == RecordLocation.Scene)
            {
                var scene = CSSceneTools.GetSceneByPath(Path);
                result = CSObjectTools.FindGameObjectInScene(scene, objectId, transformPath);
            }
            else
            {
                //var assetFile = AssetsMap.GetAssetInfoWithPath(path);
                var prefabRoot = CSPrefabTools.GetPrefabAssetRoot(Path);
                if (prefabRoot != null)
                {
                    result = CSObjectTools.FindChildGameObjectRecursive(prefabRoot.transform, objectId, prefabRoot.transform.name, transformPath);
                }
            }
            return(result);
        }
Example #14
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);
        }
Example #15
0
        private static ExactReferenceData ObjectToReferencingEntry(Object target)
        {
            var referencedObjectAsComponent = target as Component;
            var referencedObjectGameObject  = target as GameObject;

            if (referencedObjectAsComponent != null)
            {
                referencedObjectGameObject = referencedObjectAsComponent.gameObject;
            }

            if (referencedObjectGameObject == null)
            {
                Debug.LogError(Maintainer.ConstructError("Couldn't find referenced Game Object from object " + target));
                return(new ExactReferenceData());
            }

            var referencedSettings = new EntryAddSettings
            {
                componentName = referencedObjectAsComponent != null?CSComponentTools.GetComponentName(referencedObjectAsComponent) : null,
                                    componentIndex = referencedObjectAsComponent != null?CSComponentTools.GetComponentIndex(referencedObjectAsComponent) : -1,
                                                         componentInstanceId = referencedObjectAsComponent != null?referencedObjectAsComponent.GetInstanceID() : -1,
            };

            var reference = EntryGenerator.CreateNewReferenceEntry(EntryFinder.currentLocation,
                                                                   referencedObjectGameObject,
                                                                   referencedObjectGameObject, referencedSettings);

            var assetPath = CSObjectTools.TryGetObjectAssetPath(target);

            var result = new ExactReferenceData
            {
                reference = reference,
                assetPath = assetPath
            };

            return(result);
        }
Example #16
0
        public static bool ValidateFindScriptReferences(MenuCommand command)
        {
            var scriptPath = CSObjectTools.GetScriptPathFromObject(command.context);

            return(!string.IsNullOrEmpty(scriptPath) && Path.GetExtension(scriptPath).ToLower() != ".dll");
        }
        // ----------------------------------------------------------------------------
        // fix missing component
        // ----------------------------------------------------------------------------

        private static bool FixMissingComponents(GameObjectIssueRecord issue, GameObject go, bool alternative)
        {
            var touched = false;

#if UNITY_2019_1_OR_NEWER
            var removedCount = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
            if (removedCount > 0)
            {
                touched = true;
            }
#else
            if (!alternative)
            {
                CSObjectTools.SelectGameObject(go, issue.Location == RecordLocation.Scene);
            }

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

            var activeEditors = tracker.activeEditors;
            for (var i = activeEditors.Length - 1; i >= 0; i--)
            {
                var editor = activeEditors[i];
                if (editor.serializedObject.targetObject == null)
                {
                    Object.DestroyImmediate(editor.target, true);
                    touched = true;
                }
            }

            if (alternative)
            {
                return(touched);
            }

            if (!touched)
            {
                // missing script could be hidden with hide flags, so let's try select it directly and repeat
                var serializedObject = new SerializedObject(go);
                var componentsArray  = serializedObject.FindProperty("m_Component");
                if (componentsArray != null)
                {
                    for (var i = componentsArray.arraySize - 1; i >= 0; i--)
                    {
                        var componentPair   = componentsArray.GetArrayElementAtIndex(i);
                        var nestedComponent = componentPair.FindPropertyRelative("component");
                        if (nestedComponent != null)
                        {
                            if (MissingReferenceDetector.IsPropertyHasMissingReference(nestedComponent))
                            {
                                var instanceId = nestedComponent.objectReferenceInstanceIDValue;
                                if (instanceId == 0)
                                {
                                    var fileId = nestedComponent.FindPropertyRelative("m_FileID");
                                    if (fileId != null)
                                    {
                                        instanceId = fileId.intValue;
                                    }
                                }

                                Selection.instanceIDs = new [] { instanceId };
                                touched |= FixMissingComponents(issue, go, true);
                            }
                        }
                        else
                        {
                            Debug.LogError(Maintainer.LogPrefix + "Couldn't find component in component pair!");
                            break;
                        }
                    }

                    if (touched)
                    {
                        CSObjectTools.SelectGameObject(go, issue.Location == RecordLocation.Scene);
                    }
                }
                else
                {
                    Debug.LogError(Maintainer.LogPrefix + "Couldn't find components array!");
                }
            }
#endif
            if (touched)
            {
                if (issue.Location == RecordLocation.Scene)
                {
                    CSSceneTools.MarkSceneDirty();
                }
                else
                {
                    EditorUtility.SetDirty(go);
                }
            }

            return(touched);
        }
Example #18
0
        /// <summary>
        /// Get structured label of the exact reference for the output.
        /// </summary>
        /// <returns>String in format '[optional prefix] [transform path] | [component name]: [property path] [optional suffix]'.</returns>
        public string GetLabel()
        {
            if (label != null)
            {
                return(label);
            }

            labelStringBuilder = new StringBuilder();

            var needsSpace = false;

            if (!string.IsNullOrEmpty(prefixLabel))
            {
                labelStringBuilder.Append(prefixLabel);
                needsSpace = true;
            }

            if (!string.IsNullOrEmpty(transformPath))
            {
                if (needsSpace)
                {
                    labelStringBuilder.Append(' ');
                }

                string labelTransformPath;

                if (location == Location.PrefabAssetGameObject)
                {
                    var transformPathSplitterIndex = transformPath.IndexOf('/');
                    if (transformPathSplitterIndex != -1)
                    {
                        labelTransformPath = transformPath.Remove(0, transformPathSplitterIndex + 1);
                    }
                    else
                    {
                        labelTransformPath = "[Prefab Root]";
                    }
                }
                else
                {
                    labelTransformPath = transformPath;
                }

                if (labelTransformPath != null)
                {
                    labelStringBuilder.Append(labelTransformPath);
                    needsSpace = true;
                }
            }

            if (!string.IsNullOrEmpty(componentName))
            {
                if (needsSpace)
                {
                    labelStringBuilder.Append(" | ");
                }
                labelStringBuilder.Append(componentName);
                needsSpace = true;
            }

            if (!string.IsNullOrEmpty(propertyPath))
            {
                if (needsSpace)
                {
                    labelStringBuilder.Append(": ");
                }
                var nicePropertyPath = CSObjectTools.GetNicePropertyPath(propertyPath);
                labelStringBuilder.Append(nicePropertyPath);
                needsSpace = true;
            }

            if (!string.IsNullOrEmpty(suffixLabel))
            {
                if (needsSpace)
                {
                    labelStringBuilder.Append(' ');
                }
                labelStringBuilder.Append(suffixLabel);
            }

            label = labelStringBuilder.ToString();

            labelStringBuilder.Length = 0;

            return(label);
        }
Example #19
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);
            }
        }
Example #20
0
        public static ReferencingEntryData CreateNewReferenceEntry(Location currentLocation, Object lookAt, GameObject lookAtGameObject, EntryAddSettings settings)
        {
            var lookAtInstanceId = lookAt.GetInstanceID();
            CachedObjectData cachedObject;

            if (CachedObjects.ContainsKey(lookAtInstanceId))
            {
                cachedObject = CachedObjects[lookAtInstanceId];
            }
            else
            {
                cachedObject = new CachedObjectData
                {
                    objectId         = CSObjectTools.GetUniqueObjectId(lookAt),
                    objectInstanceId = lookAt.GetInstanceID(),
                };

                if (currentLocation == Location.SceneGameObject || currentLocation == Location.PrefabAssetGameObject)
                {
                    if (lookAtGameObject != null)
                    {
                        var transform = lookAtGameObject.transform;
                        cachedObject.transformPath = CSEditorTools.GetFullTransformPath(transform);
                    }
                    else
                    {
                        cachedObject.transformPath = lookAt.name;
                    }
                }
                else if (currentLocation == Location.PrefabAssetObject)
                {
                    cachedObject.transformPath = lookAt.name;
                }
                else
                {
                    cachedObject.transformPath = string.Empty;
                }

                CachedObjects.Add(lookAtInstanceId, cachedObject);
            }

            var newEntry = new ReferencingEntryData
            {
                location         = currentLocation,
                objectId         = cachedObject.objectId,
                objectInstanceId = cachedObject.objectInstanceId,
                transformPath    = cachedObject.transformPath
            };

            if (settings != null)
            {
                newEntry.componentName       = settings.componentName;
                newEntry.componentId         = settings.componentIndex;
                newEntry.componentInstanceId = settings.componentInstanceId;
                newEntry.prefixLabel         = settings.prefix;
                newEntry.suffixLabel         = settings.suffix;
                newEntry.propertyPath        = settings.propertyPath;
            }

            return(newEntry);
        }
        internal static void TryAddEntryToMatchedConjunctions(Object lookAt, int lookForInstanceId, EntryAddSettings settings)
        {
            var lookAtGameObject = lookAt as GameObject;

            for (var i = 0; i < assetConjunctions.conjunctions.Count; i++)
            {
                var conjunction            = assetConjunctions.conjunctions[i];
                var referencedAssetObjects = conjunction.referencedAsset.GetAllAssetObjects();

                var match = false;
                for (var j = 0; j < referencedAssetObjects.Length; j++)
                {
                    if (referencedAssetObjects[j] != lookForInstanceId)
                    {
                        continue;
                    }

                    match = true;
                    break;
                }

                if (!match)
                {
                    continue;
                }

                if (currentObjectCache == null)
                {
                    currentObjectCache          = new CachedObjectData();
                    currentObjectCache.objectId = CSObjectTools.GetUniqueObjectId(lookAt);

                    if (currentLocation == Location.SceneGameObject || currentLocation == Location.PrefabAssetGameObject)
                    {
                        if (lookAtGameObject != null)
                        {
                            var transform = lookAtGameObject.transform;
                            currentObjectCache.transformPath = CSEditorTools.GetFullTransformPath(transform);
                        }
                        else
                        {
                            currentObjectCache.transformPath = lookAt.name;
                        }
                    }
                    else if (currentLocation == Location.PrefabAssetObject)
                    {
                        currentObjectCache.transformPath = lookAt.name;
                    }
                    else
                    {
                        currentObjectCache.transformPath = string.Empty;
                    }
                }

                var newEntry = new ReferencingEntryData
                {
                    location      = currentLocation,
                    objectId      = currentObjectCache.objectId,
                    transformPath = currentObjectCache.transformPath
                };

                if (settings != null)
                {
                    newEntry.componentName = settings.componentName;
                    newEntry.componentId   = settings.componentIndex;
                    newEntry.prefixLabel   = settings.prefix;
                    newEntry.suffixLabel   = settings.suffix;
                    newEntry.propertyPath  = settings.propertyPath;
                }

                conjunction.referencedAtInfo.AddNewEntry(newEntry);
            }
        }
Example #22
0
        // -----------------------------------------------------------------------------
        // fix missing component
        // -----------------------------------------------------------------------------

        private static bool FixMissingComponents(GameObjectIssueRecord issue, GameObject go, bool alternative)
        {
            var touched = false;

            // TODO: re-check in Unity 2021
            // unfortunately RemoveMonoBehavioursWithMissingScript does not works correctly:
            // https://forum.unity.com/threads/remove-all-missing-components-in-prefabs.897761/
            // so it will be enabled back in later Unity versions

            /*var removedCount = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
             * if (removedCount > 0)
             * {
             *      touched = true;
             * }*/

            if (!alternative)
            {
                CSObjectTools.SelectGameObject(go, issue.Location == RecordLocation.Scene);
            }

            var tracker = CSEditorTools.GetActiveEditorTrackerForSelectedObject();

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

            var activeEditors = tracker.activeEditors;

            for (var i = activeEditors.Length - 1; i >= 0; i--)
            {
                var editor = activeEditors[i];
                if (editor.serializedObject.targetObject == null)
                {
                    Object.DestroyImmediate(editor.target, true);
                    touched = true;
                }
            }

            if (alternative)
            {
                return(touched);
            }

            if (!touched)
            {
                // missing script could be hidden with hide flags, so let's try select it directly and repeat
                var serializedObject = new SerializedObject(go);
                var componentsArray  = serializedObject.FindProperty("m_Component");
                if (componentsArray != null)
                {
                    for (var i = componentsArray.arraySize - 1; i >= 0; i--)
                    {
                        var componentPair   = componentsArray.GetArrayElementAtIndex(i);
                        var nestedComponent = componentPair.FindPropertyRelative("component");
                        if (nestedComponent != null)
                        {
                            if (MissingReferenceDetector.IsPropertyHasMissingReference(nestedComponent))
                            {
                                var instanceId = nestedComponent.objectReferenceInstanceIDValue;
                                if (instanceId == 0)
                                {
                                    var fileId = nestedComponent.FindPropertyRelative("m_FileID");
                                    if (fileId != null)
                                    {
                                        instanceId = fileId.intValue;
                                    }
                                }

                                Selection.instanceIDs = new [] { instanceId };
                                touched |= FixMissingComponents(issue, go, true);
                            }
                        }
                        else
                        {
                            Debug.LogError(Maintainer.LogPrefix + "Couldn't find component in component pair!");
                            break;
                        }
                    }

                    if (touched)
                    {
                        CSObjectTools.SelectGameObject(go, issue.Location == RecordLocation.Scene);
                    }
                }
                else
                {
                    Debug.LogError(Maintainer.LogPrefix + "Couldn't find components array!");
                }
            }

            if (touched)
            {
                if (issue.Location == RecordLocation.Scene)
                {
                    CSSceneTools.MarkSceneDirty();
                }
                else
                {
                    EditorUtility.SetDirty(go);
                }
            }

            return(touched);
        }
Example #23
0
        public void DrawFooter()
        {
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(10);

                if (SearchResultsStorage.HierarchyReferencesLastSearched.Length == 0)
                {
                    GUI.enabled = false;
                }

                if (UIHelpers.ImageButton("Refresh", "Restarts references search for the previous results.",
                                          CSIcons.Repeat))
                {
                    if (Event.current.control && Event.current.shift)
                    {
                        ReferencesFinder.debugMode = true;
                        Event.current.Use();
                    }
                    else
                    {
                        ReferencesFinder.debugMode = false;
                    }

                    EditorApplication.delayCall += () =>
                    {
                        var sceneObjects =
                            CSObjectTools.GetObjectsFromInstanceIds(SearchResultsStorage.HierarchyReferencesLastSearched);
                        HierarchyScopeReferencesFinder.FindHierarchyObjectsReferences(sceneObjects, null);
                    };
                }

                GUI.enabled = true;

                if (SearchResultsStorage.HierarchyReferencesSearchResults.Length == 0)
                {
                    GUI.enabled = false;
                }

                if (UIHelpers.ImageButton("Collapse all", "Collapses all tree items.", CSIcons.Collapse))
                {
                    treePanel.CollapseAll();
                }

                if (UIHelpers.ImageButton("Expand all", "Expands all tree items.", CSIcons.Expand))
                {
                    treePanel.ExpandAll();
                }

                if (UIHelpers.ImageButton("Clear results", "Clears results tree and empties cache.", CSIcons.Clear))
                {
                    ClearResults();
                }

                GUI.enabled = true;

                GUILayout.Space(10);
            }

            GUILayout.Space(10);
        }
Example #24
0
        public static HierarchyReferenceItem[] FindObjectsReferencesInHierarchy(Object[] objects, bool checkGameObjectsComponents, bool showResults = true)
        {
            if (UserSettings.References.clearHierarchyResults)
            {
                SearchResultsStorage.HierarchyReferencesLastSearched  = new int[0];
                SearchResultsStorage.HierarchyReferencesSearchResults = new HierarchyReferenceItem[0];
            }

            var lastSearched = SearchResultsStorage.HierarchyReferencesLastSearched;
            var allObjects   = CSObjectTools.GetObjectsFromInstanceIds(lastSearched);

            var items = new List <Object>(objects);

            if (checkGameObjectsComponents)
            {
                for (var i = items.Count - 1; i >= 0; i--)
                {
                    var item       = items[i];
                    var gameObject = item as GameObject;
                    if (gameObject == null)
                    {
                        continue;
                    }

                    var components = gameObject.GetComponents <Component>();
                    foreach (var component in components)
                    {
                        if (component == null)
                        {
                            continue;
                        }
                        if (CSObjectTools.IsHiddenInInspector(component))
                        {
                            continue;
                        }
                        items.Insert(i, component);
                    }
                }
            }

            var newItem = false;

            foreach (var o in items)
            {
                if (!ArrayUtility.Contains(allObjects, o))
                {
                    newItem = true;
                    ArrayUtility.Add(ref allObjects, o);
                }
            }

            if (items.Count == 1)
            {
                HierarchyReferencesTab.AutoSelectHierarchyReference = ObjectToReferencingEntry(items[0]).reference;
            }

            HierarchyReferenceItem[] result;

            if (newItem)
            {
                result = FindHierarchyObjectsReferences(allObjects, items.ToArray(), showResults);
            }
            else
            {
                MaintainerWindow.ShowObjectReferences();
                result = SearchResultsStorage.HierarchyReferencesSearchResults;
            }

            return(result);
        }
Example #25
0
        public static bool ValidateFindComponentReferences(MenuCommand command)
        {
            var scriptPath = CSObjectTools.GetScriptPathFromObject(command.context);

            return(!string.IsNullOrEmpty(scriptPath));
        }
Example #26
0
        public static void FindComponentReferences(MenuCommand command)
        {
            var scriptPath = CSObjectTools.GetScriptPathFromObject(command.context);

            ReferencesFinder.AddToSelectionAndRun(scriptPath);
        }
Example #27
0
        public static void FindScriptReferences(MenuCommand command)
        {
            var scriptPath = CSObjectTools.GetScriptPathFromObject(command.context);

            ReferencesFinder.FindAssetReferences(scriptPath);
        }