Пример #1
0
        public void DrawLeftColumnHeader()
        {
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(10);
                using (new GUILayout.VerticalScope())
                {
                    GUILayout.Space(10);
                    GUILayout.Label("<size=16><b>Search references of:</b></size>", UIHelpers.richLabel);
                    UIHelpers.Separator();
                    GUILayout.Space(10);

                    if (UIHelpers.ImageButton("All assets",
                                              "Traverses whole project to find where all assets are referenced.", CSIcons.Find))
                    {
                        if (Event.current.control && Event.current.shift)
                        {
                            ReferencesFinder.debugMode = true;
                            AssetsMap.Delete();
                            Event.current.Use();
                        }
                        else
                        {
                            ReferencesFinder.debugMode = false;
                        }

                        EditorApplication.delayCall += StartProjectReferencesScan;
                    }

                    if (ProjectScopeReferencesFinder.GetSelectedAssets().Length == 0)
                    {
                        GUI.enabled = false;
                    }

                    if (UIHelpers.ImageButton("Selected assets",
                                              "Adds selected Project View assets to the current search results.", CSIcons.Find))
                    {
                        EditorApplication.delayCall += () => ReferencesFinder.FindSelectedAssetsReferences();
                    }
                }
                GUILayout.Space(10);
            }

            GUI.enabled = true;
        }
Пример #2
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);
        }
Пример #3
0
        public void DrawFooter()
        {
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(10);

                if (SearchResultsStorage.ProjectReferencesLastSearched.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;
                        AssetsMap.Delete();
                        Event.current.Use();
                    }
                    else
                    {
                        ReferencesFinder.debugMode = false;
                    }

                    EditorApplication.delayCall += () =>
                    {
                        ProjectScopeReferencesFinder.FindAssetsReferences(SearchResultsStorage.ProjectReferencesLastSearched, null);
                    };
                }

                GUI.enabled = true;

                if (SearchResultsStorage.ProjectReferencesSearchResults.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))
                {
                    SearchResultsStorage.ProjectReferencesSearchResults = null;
                    SearchResultsStorage.ProjectReferencesLastSearched  = null;
                    Refresh(true);
                }

                GUI.enabled = true;

                GUILayout.Space(10);
            }
            GUILayout.Space(10);
        }
Пример #4
0
        protected override void DrawCell(ref Rect cellRect, MaintainerTreeViewItem <T> genericItem, int columnValue, RowGUIArgs args)
        {
            base.DrawCell(ref cellRect, genericItem, columnValue, args);

            var column = (Columns)columnValue;
            var item   = (ProjectReferencesTreeViewItem <T>)genericItem;

            switch (column)
            {
            case Columns.Path:

                var entryRect = DrawIconAndGetEntryRect(cellRect, item);

                Rect lastRect;

                var eyeButtonRect = entryRect;
                eyeButtonRect.width  = UIHelpers.EyeButtonSize;
                eyeButtonRect.height = UIHelpers.EyeButtonSize;
                eyeButtonRect.x     += UIHelpers.EyeButtonPadding;

                lastRect = eyeButtonRect;

                if (UIHelpers.IconButton(eyeButtonRect, CSIcons.Show))
                {
                    ShowItem(item);
                }

                if (item.depth == 1 && item.data.isReferenced)
                {
                    var findButtonRect = entryRect;
                    findButtonRect.width  = UIHelpers.EyeButtonSize;
                    findButtonRect.height = UIHelpers.EyeButtonSize;
                    findButtonRect.x     += UIHelpers.EyeButtonPadding * 2 + UIHelpers.EyeButtonSize;

                    lastRect = findButtonRect;

                    if (UIHelpers.IconButton(findButtonRect, CSIcons.Find, "Search for references"))
                    {
                        EditorApplication.delayCall += () => ProjectScopeReferencesFinder.FindAssetReferencesFromResults(item.data.assetPath);
                    }
                }

                var labelRect = entryRect;
                labelRect.xMin = lastRect.xMax + UIHelpers.EyeButtonPadding;

                if (item.data.depth == 0 && !item.data.HasChildren)
                {
                    GUI.contentColor = CSColors.labelDimmedColor;
                }
                DefaultGUI.Label(labelRect, args.label, args.selected, args.focused);

                GUI.contentColor = Color.white;

                break;

            case Columns.Type:

                DefaultGUI.Label(cellRect, item.data.assetTypeName, args.selected, args.focused);
                break;

            case Columns.Size:

                DefaultGUI.Label(cellRect, item.data.assetSizeFormatted, args.selected, args.focused);
                break;

            case Columns.ReferencesCount:

                if (item.depth == 0)
                {
                    DefaultGUI.Label(cellRect, item.data.ChildrenCount.ToString(), args.selected, args.focused);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("column", column, null);
            }
        }
Пример #5
0
 public static bool ValidateFindReferences()
 {
     return(ProjectScopeReferencesFinder.GetSelectedAssets().Length > 0);
 }