Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static HierarchyReferenceItem[] FindHierarchyObjectsReferences(Object[] allObjects, Object[] newObjects, bool showResults = true)
        {
            var results = new List <HierarchyReferenceItem>();

            try
            {
                var sw = Stopwatch.StartNew();

                CSEditorTools.lastRevealSceneOpenResult = null;
                EntryGenerator.ResetCachedObjects();

                var searchCanceled = LookForObjectsReferencesInHierarchy(allObjects, results);
                sw.Stop();

                EditorUtility.ClearProgressBar();

                if (!searchCanceled)
                {
                    var referencesFound = 0;
                    foreach (var result in results)
                    {
                        if (result.depth == 1)
                        {
                            referencesFound++;
                        }
                    }

                    if (referencesFound == 0)
                    {
                        HierarchyReferencesTab.AutoSelectHierarchyReference = null;
                        MaintainerWindow.ShowNotification("Nothing found!");
                    }
                    else
                    {
                        if (newObjects != null && newObjects.Length > 0)
                        {
                            var totalFoundFromNew = GetFoundObjects(newObjects, results);
                            if (totalFoundFromNew.Count == 0)
                            {
                                HierarchyReferencesTab.AutoSelectHierarchyReference = null;
                                MaintainerWindow.ShowNotification("Nothing found!");
                            }
                            else
                            {
                                if (HierarchyReferencesTab.AutoSelectHierarchyReference == null)
                                {
                                    if (totalFoundFromNew.Count == 1)
                                    {
                                        var firstFound = totalFoundFromNew[0];
                                        var entry      = ObjectToReferencingEntry(firstFound);
                                        HierarchyReferencesTab.AutoSelectHierarchyReference = entry.reference;
                                    }
                                }

                                MaintainerWindow.ClearNotification();
                            }
                        }
                        else
                        {
                            MaintainerWindow.ClearNotification();
                        }
                    }

                    Debug.Log(Maintainer.LogPrefix + ReferencesFinder.ModuleName + " results: " + referencesFound +
                              " references found in " + sw.Elapsed.TotalSeconds.ToString("0.000", CultureInfo.InvariantCulture) +
                              " seconds.");
                }
                else
                {
                    Debug.Log(Maintainer.LogPrefix + ReferencesFinder.ModuleName + "Search canceled by user!");
                }
            }
            catch (Exception e)
            {
                Debug.LogError(Maintainer.LogPrefix + ReferencesFinder.ModuleName + ": " + e);
                EditorUtility.ClearProgressBar();
            }

            var foundObjects = GetFoundObjects(allObjects, results);

            SaveLastSearched(foundObjects);

            EntryGenerator.ResetCachedObjects();
            SearchResultsStorage.HierarchyReferencesSearchResults = results.ToArray();

            if (showResults)
            {
                MaintainerWindow.ShowObjectReferences();
            }

            return(results.ToArray());
        }