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 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);
        }