Beispiel #1
0
        internal static ReferencesTreeElement[] FindAssetsReferences(FilterItem[] assets, bool ignoreClearOption, bool showResults)
        {
            if (MaintainerPersonalSettings.References.selectedFindClearsResults && !ignoreClearOption)
            {
                SearchResultsStorage.ReferencesFinderLastSearched = new FilterItem[0];
                SearchResultsStorage.ReferencesSearchResults      = new ReferencesTreeElement[0];
            }

            var lastSearched = SearchResultsStorage.ReferencesFinderLastSearched;

            var newItem = false;

            foreach (var asset in assets)
            {
                newItem |= CSFilterTools.TryAddNewItemToFilters(ref lastSearched, asset);
            }

            if (assets.Length == 1)
            {
                ReferencesTab.AutoSelectPath = assets[0].value;
            }

            if (newItem)
            {
                return(GetReferences(lastSearched, assets, showResults));
            }

            //ReferencesTab.AutoShowExistsNotification = true;
            MaintainerWindow.ShowReferences();

            return(SearchResultsStorage.ReferencesSearchResults);
        }
Beispiel #2
0
        /// <summary>
        /// Adds new assets to the last selection if it existed and calls a GetReferences() with extended selection;
        /// </summary>
        /// <param name="selectedAssets">Additionally selected assets.</param>
        /// <param name="showResults">Shows results in %Maintainer window if true.</param>
        /// <returns>Array of ReferencesTreeElement for the TreeView buildup or manual parsing.</returns>
        public static ReferencesTreeElement[] AddToSelectionAndRun(FilterItem[] selectedAssets, bool showResults = true)
        {
            if (MaintainerPersonalSettings.References.selectedFindClearsResults)
            {
                SearchResultsStorage.ReferencesSearchSelection = new FilterItem[0];
                SearchResultsStorage.ReferencesSearchResults   = new ReferencesTreeElement[0];
            }

            var currentSelection = SearchResultsStorage.ReferencesSearchSelection;

            var newItem = false;

            foreach (var selectedAsset in selectedAssets)
            {
                newItem |= CSFilterTools.TryAddNewItemToFilters(ref currentSelection, selectedAsset);
            }

            if (selectedAssets.Length == 1)
            {
                ReferencesTab.AutoSelectPath = selectedAssets[0].value;
            }

            if (newItem)
            {
                return(GetReferences(currentSelection, showResults));
            }

            ReferencesTab.AutoShowExistsNotification = true;
            MaintainerWindow.ShowReferences();

            return(SearchResultsStorage.ReferencesSearchResults);
        }
        internal override void ProcessDrags()
        {
            if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform)
            {
                return;
            }

            var paths = DragAndDrop.paths;

            if (paths != null && paths.Length > 0)
            {
                var canDrop = false;

                for (var i = 0; i < paths.Length; i++)
                {
                    paths[i] = CSPathTools.EnforceSlashes(paths[i]);
                    if (LooksLikeSceneFile(paths[i]))
                    {
                        canDrop = true;
                        break;
                    }
                }

                if (canDrop)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (currentEventType == EventType.DragPerform)
                    {
                        var needToSave        = false;
                        var needToShowWarning = false;

                        foreach (var path in paths)
                        {
                            if (LooksLikeSceneFile(path))
                            {
                                var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(path, FilterKind.Path));
                                needToSave        |= added;
                                needToShowWarning |= !added;
                            }
                        }

                        if (needToSave)
                        {
                            SaveChanges();
                        }

                        if (needToShowWarning)
                        {
                            window.ShowNotification(new GUIContent("One or more of the dragged items already present in the list!"));
                        }

                        DragAndDrop.AcceptDrag();
                    }
                }
            }
            Event.current.Use();
        }
Beispiel #4
0
        internal override void ProcessDrags()
        {
            if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform)
            {
                return;
            }

            var paths            = DragAndDrop.paths;
            var objectReferences = DragAndDrop.objectReferences;

            if (paths != null && objectReferences != null && paths.Length > 0 && paths.Length == objectReferences.Length)
            {
                var atLeastOneFileAsset = objectReferences.Any(AssetDatabase.Contains);
                if (!atLeastOneFileAsset)
                {
                    return;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (currentEventType == EventType.DragPerform)
                {
                    for (var i = 0; i < objectReferences.Length; i++)
                    {
                        paths[i] = CSPathTools.EnforceSlashes(AssetDatabase.GetAssetPath(objectReferences[i]));
                    }

                    var needToSave        = false;
                    var needToShowWarning = false;

                    foreach (var path in paths)
                    {
                        var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(path, FilterKind.Path));
                        needToSave        |= added;
                        needToShowWarning |= !added;
                    }

                    if (needToSave)
                    {
                        SaveChanges();
                    }

                    if (needToShowWarning)
                    {
                        window.ShowNotification(new GUIContent("One or more of the dragged items already present in the list!"));
                    }

                    DragAndDrop.AcceptDrag();
                }
            }
            Event.current.Use();
        }
Beispiel #5
0
        protected virtual void DrawAddItemSection()
        {
            EditorGUILayout.LabelField(GetAddNewLabel());
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(6);
                GUI.SetNextControlName("AddButton");

                var flag = currentEvent.isKey && Event.current.type == EventType.KeyDown && (currentEvent.keyCode == KeyCode.Return || currentEvent.keyCode == KeyCode.KeypadEnter);
                if (UIHelpers.IconButton(CSIcons.Plus, "Adds custom filter to the list.") || flag)
                {
                    if (string.IsNullOrEmpty(newItemText))
                    {
                        window.ShowNotification(new GUIContent("You can't add an empty filter!"));
                    }
                    else if (newItemText.IndexOf('*') != -1)
                    {
                        window.ShowNotification(new GUIContent("Masks are not supported!"));
                    }
                    else
                    {
                        if (newItemKind == FilterKind.Extension && !newItemText.StartsWith("."))
                        {
                            newItemText = "." + newItemText;
                        }

                        if (CheckNewItem(ref newItemText))
                        {
                            if (CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(newItemText, newItemKind, newItemIgnoreCase)))
                            {
                                SaveChanges();
                                newItemText = "";
                                GUI.FocusControl("AddButton");
                                didFocus = false;
                            }
                            else
                            {
                                window.ShowNotification(new GUIContent("This filter already exists in the list!"));
                            }
                        }
                    }
                }
                if (flag)
                {
                    currentEvent.Use();
                    currentEvent.Use();
                }

                newItemKind       = DrawFilterKindDropdown(newItemKind);
                newItemIgnoreCase = DrawFilterIgnoreCaseToggle(newItemIgnoreCase);
                GUILayout.Space(5);

                GUI.SetNextControlName("filtersTxt");
                newItemText = EditorGUILayout.TextField(newItemText);
                if (!didFocus)
                {
                    didFocus = true;
                    EditorGUI.FocusTextInControl("filtersTxt");
                }
            }
        }
Beispiel #6
0
        internal override void ProcessDrags()
        {
            if (currentEventType != EventType.DragUpdated && currentEventType != EventType.DragPerform)
            {
                return;
            }

            var objects = DragAndDrop.objectReferences;

            if (objects != null && objects.Length > 0)
            {
                var canDrop = false;

                for (var i = 0; i < objects.Length; i++)
                {
                    if (objects[i] is Component)
                    {
                        canDrop = true;
                        break;
                    }

                    var monoScript = objects[i] as MonoScript;
                    if (monoScript != null)
                    {
                        var type = monoScript.GetClass();
                        if (type.IsSubclassOf(CSReflectionTools.componentType))
                        {
                            canDrop = true;
                            break;
                        }
                    }
                }

                if (canDrop)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (currentEventType == EventType.DragPerform)
                    {
                        var needToSave        = false;
                        var needToShowWarning = false;
                        var noComponent       = false;
                        var invalidComponent  = false;

                        for (var i = 0; i < objects.Length; i++)
                        {
                            var    component     = objects[i] as Component;
                            var    monoScript    = objects[i] as MonoScript;
                            string componentName = null;

                            if (component != null)
                            {
                                componentName = component.GetType().Name;
                            }
                            else if (monoScript != null)
                            {
                                var type = monoScript.GetClass();
                                if (type.IsSubclassOf(CSReflectionTools.componentType))
                                {
                                    componentName = type.Name;
                                }
                                else
                                {
                                    noComponent = true;
                                }
                            }
                            else
                            {
                                noComponent = true;
                            }

                            if (noComponent)
                            {
                                continue;
                            }

                            if (!string.IsNullOrEmpty(componentName) && componentName != "Object" && componentName != "Component" && componentName != "Behaviour")
                            {
                                var added = CSFilterTools.TryAddNewItemToFilters(ref filters, FilterItem.Create(componentName, FilterKind.Type));
                                needToSave        |= added;
                                needToShowWarning |= !added;
                            }
                            else
                            {
                                invalidComponent = true;
                            }
                        }

                        if (needToSave)
                        {
                            SaveChanges();
                        }

                        var warningText = "";

                        if (needToShowWarning)
                        {
                            warningText = "One or more of the dragged items already present in the list!";
                        }

                        if (noComponent)
                        {
                            if (!string.IsNullOrEmpty(warningText))
                            {
                                warningText += "\n";
                            }
                            warningText += "One or more of the dragged items are not the Components!";
                        }

                        if (invalidComponent)
                        {
                            if (!string.IsNullOrEmpty(warningText))
                            {
                                warningText += "\n";
                            }
                            warningText += "Can't detect valid name for one or more of the dragged items!";
                        }

                        if (!string.IsNullOrEmpty(warningText))
                        {
                            window.ShowNotification(new GUIContent(warningText));
                        }

                        DragAndDrop.AcceptDrag();
                    }
                }
            }
            Event.current.Use();
        }