Beispiel #1
0
        public void             SelectEntry(int i)
        {
            this.selectedEntry = i;

            if (this.selectedEntry == -1)
            {
                GUI.FocusControl("content");
            }
            else
            {
                GUI.FocusControl(null);

                List <EntryRef> list;

                if (string.IsNullOrEmpty(this.keywords) == true && this.filterInstances.Count == 0)
                {
                    list = NGSpotlightWindow.lastUsed;
                }
                else
                {
                    list = this.results;
                }

                EntryRef k = list[this.selectedEntry];
                NGSpotlightWindow.entries[k.key][k.i].Select(this, k);
            }
        }
Beispiel #2
0
 void IDrawableElement.Execute(NGSpotlightWindow window, EntryRef key)
 {
     if (EditorApplication.ExecuteMenuItem(this.path) == true)
     {
         NGSpotlightWindow.UseEntry(key);
     }
 }
Beispiel #3
0
        void IDrawableElement.Execute(NGSpotlightWindow window, EntryRef key)
        {
            NGSpotlightWindow.UseEntry(key);
            Object file = AssetDatabase.LoadAssetAtPath <Object>(this.path);

            EditorGUIUtility.PingObject(file);
            AssetDatabase.OpenAsset(file, 0);
        }
Beispiel #4
0
        void IDrawableElement.OnGUI(Rect r, NGSpotlightWindow window, EntryRef k, int i)
        {
            if (MenuItemDrawer.style == null)
            {
                MenuItemDrawer.style              = new GUIStyle(EditorStyles.label);
                MenuItemDrawer.style.alignment    = TextAnchor.MiddleLeft;
                MenuItemDrawer.style.padding.left = 32;
                MenuItemDrawer.style.fontSize     = 15;
                MenuItemDrawer.style.richText     = true;
            }

            GUI.Box(r, "");

            if (Event.current.type == EventType.Repaint)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().hoverSelectionColor : NGSpotlightWindow.HighlightedEntryColor);
                }
                else if (window.selectedEntry == i)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().outlineSelectionColor : NGSpotlightWindow.SelectedEntryColor);
                }
            }

            if (this.lastChange != window.changeCount)
            {
                this.lastChange            = window.changeCount;
                this.cachedHighlightedName = window.HighlightWeightContent(this.lowerPath, this.path, window.cleanLowerKeywords);
            }

            //GUI.DrawTexture(iconR, this.icon, ScaleMode.ScaleToFit);
            GUI.Label(r, this.cachedHighlightedName, MenuItemDrawer.style);

            if ((Event.current.type == EventType.KeyDown && window.selectedEntry == i && Event.current.keyCode == KeyCode.Return) ||
                (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition) == true))
            {
                if (EditorApplication.ExecuteMenuItem(this.path) == true)
                {
                    NGSpotlightWindow.UseEntry(k);
                }
                window.Close();
                Event.current.Use();
            }
        }
Beispiel #5
0
        protected virtual void  OnDisable()
        {
            Utility.UnregisterWindow(this);

            List <EntryHardRef> refs = new List <EntryHardRef>(NGSpotlightWindow.lastUsed.Count);

            for (int i = 0; i < NGSpotlightWindow.lastUsed.Count; i++)
            {
                EntryRef k = NGSpotlightWindow.lastUsed[i];

                refs.Add(new EntryHardRef()
                {
                    key = k.key, content = NGSpotlightWindow.entries[k.key][k.i].RawContent
                });
            }

            Utility.DirectSaveEditorPref(refs, typeof(List <EntryHardRef>), NGSpotlightWindow.Title + ".lastUsed");
        }
Beispiel #6
0
        public static void      UseEntry(EntryRef m)
        {
            for (int i = 0; i < NGSpotlightWindow.lastUsed.Count; i++)
            {
                if (NGSpotlightWindow.lastUsed[i].key == m.key &&
                    NGSpotlightWindow.lastUsed[i].i == m.i)
                {
                    NGSpotlightWindow.lastUsed.RemoveAt(i);
                    break;
                }
            }

            NGSpotlightWindow.lastUsed.Insert(0, m);

            if (NGSpotlightWindow.lastUsed.Count > NGSpotlightWindow.MaxLastUsed)
            {
                NGSpotlightWindow.lastUsed.RemoveAt(NGSpotlightWindow.lastUsed.Count - 1);
            }
        }
Beispiel #7
0
        protected virtual void  OnGUI()
        {
            List <EntryRef> list;

            if (string.IsNullOrEmpty(this.keywords) == true && this.filterInstances.Count == 0)
            {
                list = NGSpotlightWindow.lastUsed;
            }
            else
            {
                list = this.results;
            }

            Rect r = new Rect(0F, 0F, this.position.width, 18F);

            if (this.focusTextfieldOnce == false && Event.current.type == EventType.Repaint)
            {
                this.focusTextfieldOnce = true;
                GUI.FocusControl("content");
                EditorGUIUtility.editingTextField = true;
            }

            if (Event.current.type == EventType.MouseMove)
            {
                this.Repaint();
            }
            else if (Event.current.type == EventType.ValidateCommand)
            {
                if (Event.current.commandName == "SelectAll" ||
                    Event.current.commandName == "Copy" ||
                    Event.current.commandName == "Paste" ||
                    Event.current.commandName == "Cut")
                {
                    this.displayHotkeyOnControlPressed = false;
                }
            }
            else if (Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode == KeyCode.LeftControl || Event.current.keyCode == KeyCode.RightControl)
                {
                    if (this.consummedKeydown == false)
                    {
                        this.consummedKeydown = true;
                        this.displayHotkeyOnControlPressed = !this.displayHotkeyOnControlPressed;
                        this.Repaint();
                    }
                }
                else if (this.displayHotkeyOnControlPressed == true &&
                         ((Event.current.keyCode >= KeyCode.Alpha1 && Event.current.keyCode <= KeyCode.Alpha9) ||
                          (Event.current.keyCode >= KeyCode.Keypad1 && Event.current.keyCode <= KeyCode.Keypad9)))
                {
                    int n;

                    if (Event.current.keyCode >= KeyCode.Alpha1 && Event.current.keyCode <= KeyCode.Alpha9)
                    {
                        n = (int)(Event.current.keyCode - KeyCode.Alpha1);
                    }
                    else
                    {
                        n = (int)(Event.current.keyCode - KeyCode.Keypad1);
                    }

                    EntryRef er = list[n];
                    List <IDrawableElement> registry = NGSpotlightWindow.entries[er.key];

                    if (er.i < registry.Count)
                    {
                        registry[er.i].Execute(this, er);
                        this.Close();
                        Event.current.Use();
                    }
                }
                else if (Event.current.character == ':' || Event.current.keyCode == KeyCode.Space)
                {
                    if (this.selectedFilter >= 0 || this.selectedEntry >= 0)
                    {
                        this.selectedFilter     = -1;
                        this.selectedEntry      = -1;
                        this.focusTextfieldOnce = false;
                    }
                }
                else if (Event.current.keyCode == KeyCode.Escape)
                {
                    this.Close();
                    Event.current.Use();
                }
                else if (Event.current.keyCode == KeyCode.Delete)
                {
                    if (this.selectedFilter >= 0)
                    {
                        this.RemoveFilterInstance(this.filterInstances[this.selectedFilter]);

                        while (this.selectedFilter >= this.filterInstances.Count)
                        {
                            --this.selectedFilter;
                        }

                        if (this.filterInstances.Count == 0)
                        {
                            this.focusTextfieldOnce = false;
                        }
                    }
                }
                else if (Event.current.keyCode == KeyCode.Backspace)
                {
                    if (Event.current.control == true)
                    {
                        this.displayHotkeyOnControlPressed = false;
                    }

                    if (this.selectedEntry == -1 && this.keywords.Length == 0 && this.filterInstances.Count > 0)
                    {
                        if (this.selectedFilter == -1)
                        {
                            this.selectedFilter = this.filterInstances.Count - 1;
                        }
                        else if (this.selectedFilter >= 0)
                        {
                            this.RemoveFilterInstance(this.filterInstances[this.selectedFilter]);

                            while (this.selectedFilter >= this.filterInstances.Count)
                            {
                                --this.selectedFilter;
                            }

                            if (this.filterInstances.Count == 0)
                            {
                                this.focusTextfieldOnce = false;
                            }
                        }
                        GUI.FocusControl(null);
                    }
                }
                else if (Event.current.keyCode == KeyCode.LeftArrow)
                {
                    if (Event.current.control == true)
                    {
                        this.displayHotkeyOnControlPressed = false;
                    }

                    if (this.selectedEntry == -1 && this.keywords.Length == 0 && this.filterInstances.Count > 0)
                    {
                        if (this.selectedFilter == -1)
                        {
                            this.selectedFilter = this.filterInstances.Count - 1;
                        }
                        else if (this.selectedFilter > 0)
                        {
                            --this.selectedFilter;
                        }
                        GUI.FocusControl(null);
                    }
                }
                else if (Event.current.keyCode == KeyCode.RightArrow)
                {
                    if (Event.current.control == true)
                    {
                        this.displayHotkeyOnControlPressed = false;
                    }

                    if (this.selectedEntry == -1 && this.keywords.Length == 0 && this.filterInstances.Count > 0)
                    {
                        if (this.selectedFilter < this.filterInstances.Count - 1)
                        {
                            ++this.selectedFilter;
                        }
                        else if (this.selectedFilter == this.filterInstances.Count - 1)
                        {
                            this.selectedFilter     = -1;
                            this.focusTextfieldOnce = false;
                        }
                    }
                }
                else if (Event.current.keyCode == KeyCode.Return ||
                         Event.current.keyCode == KeyCode.KeypadEnter)
                {
                    if (list.Count > 0)
                    {
                        int n = this.selectedEntry;

                        if (n == -1)
                        {
                            if (EditorGUIUtility.editingTextField == false)
                            {
                                return;
                            }

                            n = 0;
                        }

                        EntryRef er = list[n];
                        List <IDrawableElement> registry = NGSpotlightWindow.entries[er.key];

                        if (er.i < registry.Count)
                        {
                            registry[er.i].Execute(this, er);
                            this.Close();
                            Event.current.Use();
                        }
                    }
                }
                else if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    if (this.selectedEntry + 1 < list.Count)
                    {
                        if (GUI.GetNameOfFocusedControl() == "content")
                        {
                            GUI.FocusControl(null);
                        }
                        this.selectedFilter = -1;

                        this.SelectEntry(this.selectedEntry + 1);
                        this.ClampScrollbarOffsetToSelectedEntry();

                        Event.current.Use();
                    }
                }
                else if (Event.current.keyCode == KeyCode.UpArrow)
                {
                    if (this.selectedEntry >= 0)
                    {
                        this.selectedFilter = -1;
                        this.SelectEntry(this.selectedEntry - 1);
                        this.ClampScrollbarOffsetToSelectedEntry();

                        Event.current.Use();
                    }
                }
                else if (Event.current.keyCode == KeyCode.PageUp)
                {
                    if (this.selectedEntry >= 0)
                    {
                        this.selectedFilter = -1;

                        if (this.selectedEntry > 1)
                        {
                            this.SelectEntry(Mathf.Max(0, this.selectedEntry - Mathf.FloorToInt((this.position.height - 18F) / NGSpotlightWindow.RowHeight)));
                        }
                        else
                        {
                            this.SelectEntry(-1);
                        }

                        this.ClampScrollbarOffsetToSelectedEntry();

                        Event.current.Use();
                    }
                }
                else if (Event.current.keyCode == KeyCode.PageDown)
                {
                    if (this.selectedEntry + 1 < list.Count)
                    {
                        this.selectedFilter = -1;

                        if (GUI.GetNameOfFocusedControl() == "content")
                        {
                            GUI.FocusControl(null);
                        }

                        this.SelectEntry(Mathf.Min(list.Count - 1, this.selectedEntry + Mathf.CeilToInt((this.position.height - 18F) / NGSpotlightWindow.RowHeight)));
                        this.ClampScrollbarOffsetToSelectedEntry();

                        Event.current.Use();
                    }
                }
                else if (Event.current.keyCode == KeyCode.Home && GUI.GetNameOfFocusedControl() != "content")
                {
                    this.selectedFilter = -1;
                    this.SelectEntry(-1);
                    this.scrollbar.Offset = 0F;
                    Event.current.Use();
                }
                else if (Event.current.keyCode == KeyCode.End && GUI.GetNameOfFocusedControl() != "content")
                {
                    this.selectedFilter = -1;
                    this.SelectEntry(list.Count - 1);
                    this.scrollbar.Offset = -this.scrollbar.MaxHeight + (this.selectedEntry + 1) * (NGSpotlightWindow.RowHeight + NGSpotlightWindow.Spacing) - NGSpotlightWindow.Spacing;
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.KeyUp)
            {
                this.consummedKeydown = false;
                //this.displayHotkeyOnControlPressed = Event.current.control;
                this.Repaint();
            }

            if (this.filterInstances.Count > 0)
            {
                for (int i = 0; i < this.filterInstances.Count; i++)
                {
                    using (BgColorContentRestorer.Get(this.selectedFilter == i, Color.green))
                    {
                        r.width = this.filterInstances[i].GetWidth();
                        this.filterInstances[i].OnGUI(r, this);
                        r.x += r.width + 2F;
                    }
                }

                r.width = this.position.width - r.x;
            }

            r.xMax -= NGSpotlightWindow.DropdownWidth;

            EditorGUI.BeginChangeCheck();
            GUI.SetNextControlName("content");
            this.keywords = EditorGUI.TextField(r, this.keywords);
            if (EditorGUI.EndChangeCheck() == true)
            {
                this.RefreshResult();
            }

            if (string.IsNullOrEmpty(this.keywords) == true)
            {
                GUI.enabled = false;
                r.x        += 4F;
                GUI.Label(r, NGSpotlightWindow.KeywordsPlaceholder);
                r.x        -= 4F;
                GUI.enabled = true;
            }

            r.xMin += r.width;
            r.width = NGSpotlightWindow.DropdownWidth;
            if (GUI.Button(r, "", GeneralStyles.ToolbarDropDown) == true)
            {
                GenericMenu menu = new GenericMenu();
                GenericMenu.MenuFunction rawExport         = (this.results.Count > 0) ? new GenericMenu.MenuFunction(this.ExportRawResults) : null;
                GenericMenu.MenuFunction exportWithContext = (this.results.Count > 0) ? new GenericMenu.MenuFunction(this.ExportResultsWithContext) : null;

                menu.AddItem(new GUIContent("Raw export"), false, rawExport);
                menu.AddItem(new GUIContent("Export with context"), false, exportWithContext);
                menu.AddItem(new GUIContent("Settings"), false, this.OpenSettings);

                menu.DropDown(r);
            }

            if (GUI.GetNameOfFocusedControl() == "content")
            {
                this.selectedFilter = -1;
                this.selectedEntry  = -1;
            }

            r.x     = 0F;
            r.y    += r.height;
            r.width = this.position.width;

            if (this.error.Count > 0)
            {
                for (int i = 0; i < this.error.Count; i++)
                {
                    Utility.content.text = this.error[i];
                    // Helpbox style does not calculate the height correctly.
                    r.height = Mathf.Max(NGSpotlightWindow.RowHeight, EditorStyles.helpBox.CalcHeight(Utility.content, r.width - 50F));                     // Reduce the width to ensure we display everything with a bit of luck.
                    EditorGUI.HelpBox(r, this.error[i], MessageType.Warning);
                    r.y += r.height;
                }
            }

            if (this.keywords.Length > 0 && this.keywords[0] == ':' && this.IsValidFilter() == false)
            {
                r.height = 16F;

                using (LabelWidthRestorer.Get(60F))
                {
                    for (int i = 0; i < this.availableFilters.Count; i++)
                    {
                        EditorGUIUtility.AddCursorRect(r, MouseCursor.Link);

                        if (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true)
                        {
                            if (this.availableFilters[i].key.Contains("=") == false && this.availableFilters[i].key.Contains("{") == false)
                            {
                                this.keywords = this.availableFilters[i].key + ' ';
                            }
                            else
                            {
                                this.keywords = this.availableFilters[i].key;
                            }
                            this.RefreshResult();
                            GUI.FocusControl(null);
                            this.focusTextfieldOnce = false;
                            this.Repaint();
                            Event.current.Use();
                        }

                        if (this.availableFilters[i].icon != null)
                        {
                            using (LabelWidthRestorer.Get(80F - 16F))
                            {
                                Rect iconR = r;

                                r.xMin += 16F;
                                EditorGUI.LabelField(r, this.availableFilters[i].key, this.availableFilters[i].description);

                                iconR.width = iconR.height;
                                GUI.DrawTexture(iconR, this.availableFilters[i].icon, ScaleMode.ScaleToFit);
                                r.xMin -= 16F;
                            }
                        }
                        else
                        {
                            using (LabelWidthRestorer.Get(80F))
                            {
                                EditorGUI.LabelField(r, this.availableFilters[i].key, this.availableFilters[i].description);
                            }
                        }
                        r.y += r.height + 2F;
                    }
                }

                EditorGUI.HelpBox(new Rect(0F, this.position.height - NGSpotlightWindow.RowHeight, this.position.width, NGSpotlightWindow.RowHeight), "Add a space to validate the filter.", MessageType.Info);
            }
            else
            {
                r.height = NGSpotlightWindow.RowHeight;

                this.scrollbar.ClearInterests();
                if (this.selectedEntry != -1)
                {
                    this.scrollbar.AddInterest(this.selectedEntry * (NGSpotlightWindow.RowHeight + NGSpotlightWindow.Spacing) + NGSpotlightWindow.RowHeight * .5F, Color.yellow);
                }

                this.scrollbar.RealHeight = list.Count * (NGSpotlightWindow.RowHeight + NGSpotlightWindow.Spacing) - NGSpotlightWindow.Spacing;
                this.scrollbar.SetPosition(this.position.width - 15F, r.y);
                this.scrollbar.SetSize(this.position.height - r.y);
                this.scrollbar.OnGUI();

                GUI.BeginClip(new Rect(0F, r.y, this.position.width, this.position.height - r.y));
                {
                    r.y      = -this.scrollbar.Offset;
                    r.width -= this.scrollbar.MaxWidth;

                    for (int i = 0; i < list.Count; i++)
                    {
                        if (r.y + r.height <= 0)
                        {
                            r.y += r.height + NGSpotlightWindow.Spacing;
                            continue;
                        }

                        List <IDrawableElement> registry;

                        if (NGSpotlightWindow.entries.TryGetValue(list[i].key, out registry) == true)
                        {
                            if (list[i].i < registry.Count)
                            {
                                NGSpotlightWindow.entries[list[i].key][list[i].i].OnGUI(r, this, list[i], i);

                                if (this.displayHotkeyOnControlPressed == true && i < 9)
                                {
                                    Rect numberR = r;
                                    numberR.width = numberR.height;

                                    EditorGUI.DrawRect(numberR, Color.cyan * .6F);

                                    using (ColorContentRestorer.Get(Color.black))
                                    {
                                        GUI.Label(numberR, (i + 1).ToCachedString(), GeneralStyles.MainTitle);
                                    }
                                }
                            }
                            else
                            {
                                list.RemoveAt(i--);
                            }
                        }
                        else
                        {
                            list.RemoveAt(i--);
                        }

                        r.y += r.height + NGSpotlightWindow.Spacing;

                        if (r.y > this.scrollbar.MaxHeight)
                        {
                            break;
                        }
                    }
                }
                GUI.EndClip();
            }
        }
Beispiel #8
0
        void IDrawableElement.OnGUI(Rect r, NGSpotlightWindow window, EntryRef k, int i)
        {
            // Init once.
            if (this.lastChange == -1)
            {
                this.asset = AssetDatabase.LoadAssetAtPath(this.path, typeof(Object));
            }

            if (this.asset == null)
            {
                NGSpotlightWindow.DeleteEntry(k.key, k.i);
                return;
            }

            if (DefaultAssetDrawer.style == null)
            {
                DefaultAssetDrawer.style           = new GUIStyle(EditorStyles.label);
                DefaultAssetDrawer.style.alignment = TextAnchor.MiddleLeft;
                DefaultAssetDrawer.style.fontSize  = 15;
                DefaultAssetDrawer.style.richText  = true;

                DefaultAssetDrawer.defaultIcon = InternalEditorUtility.GetIconForFile(".png");
            }

            if (this.iconIsPreview == true && this.asset != null && (this.icon == null || this.icon == DefaultAssetDrawer.defaultIcon))
            {
                this.icon = AssetPreview.GetAssetPreview(this.asset);
                window.Repaint();
            }

            if (this.icon == null)
            {
                this.icon = DefaultAssetDrawer.defaultIcon;
            }

            Rect iconR = r;

            iconR.width = iconR.height;

            GUI.Box(r, "");
            GUI.DrawTexture(iconR, this.icon, ScaleMode.ScaleToFit);

            if (this.lastChange != window.changeCount)
            {
                this.lastChange            = window.changeCount;
                this.cachedHighlightedName = window.HighlightWeightContent(this.lowerName, this.name, window.cleanLowerKeywords);
            }

            if (Event.current.type == EventType.Repaint)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().hoverSelectionColor : NGSpotlightWindow.HighlightedEntryColor);
                }
                if (window.selectedEntry == i)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().outlineSelectionColor : NGSpotlightWindow.SelectedEntryColor);
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                if (i.Equals(DragAndDrop.GetGenericData("i")) == true)
                {
                    DragAndDrop.StartDrag("Drag Asset");
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.MouseDown)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.SetGenericData("i", i);
                    DragAndDrop.objectReferences = new Object[] { this.asset };
                }
            }
            else if (Event.current.type == EventType.DragExited)
            {
                DragAndDrop.PrepareStartDrag();
            }

            if ((Event.current.type == EventType.KeyDown && window.selectedEntry == i && Event.current.keyCode == KeyCode.Return) ||
                (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true && i.Equals(DragAndDrop.GetGenericData("i")) == true))
            {
                if (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.PrepareStartDrag();
                }

                if (window.selectedEntry == i || Event.current.button != 0)
                {
                    NGSpotlightWindow.UseEntry(k);
                    Selection.activeObject = this.asset;
                    window.Close();
                }
                else
                {
                    window.SelectEntry(i);
                }

                Event.current.Use();
            }

            r.xMin += iconR.width;
            GUI.Label(r, this.cachedHighlightedName, DefaultAssetDrawer.style);
        }
Beispiel #9
0
 void IDrawableElement.Execute(NGSpotlightWindow window, EntryRef key)
 {
     NGSpotlightWindow.UseEntry(key);
     EditorGUIUtility.PingObject(this.asset);
     Selection.activeObject = this.asset;
 }
Beispiel #10
0
 void IDrawableElement.Select(NGSpotlightWindow window, EntryRef key)
 {
     EditorGUIUtility.PingObject(this.asset);
 }
Beispiel #11
0
        void IDrawableElement.OnGUI(Rect r, NGSpotlightWindow window, EntryRef k, int i)
        {
            // Init once.
            if (this.lastChange == -1)
            {
                this.go = AssetDatabase.LoadAssetAtPath <GameObject>(this.path);
            }

            if (this.go == null)
            {
                NGSpotlightWindow.DeleteEntry(k.key, k.i);
                return;
            }

            if (PrefabDrawer.style == null)
            {
                PrefabDrawer.style           = new GUIStyle(EditorStyles.label);
                PrefabDrawer.style.alignment = TextAnchor.MiddleLeft;
                PrefabDrawer.style.fontSize  = 15;
                PrefabDrawer.style.richText  = true;
            }

            Rect iconR = r;

            iconR.width = iconR.height;

            GUI.Box(r, "");
            GUI.DrawTexture(iconR, UtilityResources.PrefabIcon, ScaleMode.ScaleToFit);

            if (this.lastChange != window.changeCount)
            {
                this.lastChange = window.changeCount;

                if (this.cachedHierarchy == null)
                {
                    if (this.go != null && this.go.transform.parent != null)
                    {
                        //this.cachedHierarchy = Utility.GetHierarchyStringified(this.go.transform.parent) + '/';
                        this.cachedHierarchy = "<color=teal><size=9>" + this.go.transform.parent.name + '/' + "</size></color>";
                    }
                    else
                    {
                        this.cachedHierarchy = string.Empty;
                    }
                }

                this.cachedHighlightedName = this.cachedHierarchy + window.HighlightWeightContent(this.lowerName, this.name, window.cleanLowerKeywords);
                //this.cachedHighlightedName = window.HighlightWeightContent(this.lowerName, this.name, window.cleanLowerKeywords);
            }

            if (Event.current.type == EventType.Repaint)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().hoverSelectionColor : NGSpotlightWindow.HighlightedEntryColor);
                }
                else if (window.selectedEntry == i)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().outlineSelectionColor : NGSpotlightWindow.SelectedEntryColor);
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                if (i.Equals(DragAndDrop.GetGenericData("i")) == true)
                {
                    DragAndDrop.StartDrag("Drag Asset");
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.MouseDown)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.SetGenericData("i", i);
                    DragAndDrop.objectReferences = new Object[] { this.go };
                }
            }
            else if (Event.current.type == EventType.DragExited)
            {
                DragAndDrop.PrepareStartDrag();
            }

            if ((Event.current.type == EventType.KeyDown && window.selectedEntry == i && Event.current.keyCode == KeyCode.Return) ||
                (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true && i.Equals(DragAndDrop.GetGenericData("i")) == true))
            {
                if (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.PrepareStartDrag();
                }

                if (window.selectedEntry == i || Event.current.button != 0)
                {
                    NGSpotlightWindow.UseEntry(k);
                    Selection.activeGameObject = this.go;
                    window.Close();
                }
                else
                {
                    window.SelectEntry(i);
                }

                Event.current.Use();
            }

            r.xMin += iconR.width;
            GUI.Label(r, this.cachedHighlightedName, PrefabDrawer.style);
        }
Beispiel #12
0
 void IDrawableElement.Select(NGSpotlightWindow window, EntryRef key)
 {
 }
Beispiel #13
0
        void IDrawableElement.OnGUI(Rect r, NGSpotlightWindow window, EntryRef k, int i)
        {
            if (CSharpDrawer.style == null)
            {
                CSharpDrawer.style           = new GUIStyle(EditorStyles.label);
                CSharpDrawer.style.alignment = TextAnchor.MiddleLeft;
                CSharpDrawer.style.fontSize  = 15;
                CSharpDrawer.style.richText  = true;
            }

            if (this.type == null)
            {
                var mn = AssetDatabase.LoadAssetAtPath <MonoScript>(this.path);
                if (mn)
                {
                    this.type = mn.GetClass();
                }
            }

            Rect iconR = r;

            iconR.width = iconR.height;

            GUI.Box(r, "");

            if (Event.current.type == EventType.Repaint)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().hoverSelectionColor : NGSpotlightWindow.HighlightedEntryColor);
                }
                else if (window.selectedEntry == i)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().outlineSelectionColor : NGSpotlightWindow.SelectedEntryColor);
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                if (i.Equals(DragAndDrop.GetGenericData("i")) == true)
                {
                    DragAndDrop.StartDrag("Drag Asset");
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.MouseDown)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.SetGenericData("i", i);
                    DragAndDrop.objectReferences = new Object[] { AssetDatabase.LoadAssetAtPath <Object>(this.path) };
                }
            }
            else if (Event.current.type == EventType.DragExited)
            {
                DragAndDrop.PrepareStartDrag();
            }

            GUI.DrawTexture(iconR, UtilityResources.CSharpIcon, ScaleMode.ScaleToFit);

            if (this.lastChange != window.changeCount)
            {
                this.lastChange            = window.changeCount;
                this.cachedHighlightedName = window.HighlightWeightContent(this.lowerName, this.name, window.cleanLowerKeywords);
            }

            float h  = Mathf.Floor(r.height * .66F);
            Rect  r3 = r;

            r3.height = h;
            r3.xMin  += iconR.width;
            r3.xMax  -= CSharpDrawer.OpenWidth;
            GUI.Label(r3, this.cachedHighlightedName, CSharpDrawer.style);

            if (this.type != null)
            {
                r3.y     += r3.height - 2F;
                r3.height = iconR.height - h + 4F;
                GUI.Label(r3, this.type.FullName, GeneralStyles.SmallLabel);
                r3.y = iconR.y;
            }

            Rect openR = r3;

            openR.height = iconR.height;
            openR.y     += (openR.height - h) * .5F;
            openR.height = h;
            openR.x     += openR.width;
            openR.width  = CSharpDrawer.OpenWidth;
            if (GUI.Button(openR, "Open") == true)
            {
                EditorUtility.OpenWithDefaultApp(this.path);
            }

            if ((Event.current.type == EventType.KeyDown && window.selectedEntry == i && Event.current.keyCode == KeyCode.Return) ||
                (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true && openR.Contains(Event.current.mousePosition) == false && i.Equals(DragAndDrop.GetGenericData("i")) == true))
            {
                if (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true && openR.Contains(Event.current.mousePosition) == false)
                {
                    DragAndDrop.PrepareStartDrag();
                }

                if (window.selectedEntry == i || Event.current.button != 0)
                {
                    NGSpotlightWindow.UseEntry(k);

                    Object file = AssetDatabase.LoadAssetAtPath <Object>(this.path);

                    if (Event.current.button == 0)
                    {
                        AssetDatabase.OpenAsset(file, 0);
                    }
                    else
                    {
                        Selection.activeObject = file;
                    }

                    window.Close();
                }
                else
                {
                    window.SelectEntry(i);
                }

                Event.current.Use();
            }
        }
Beispiel #14
0
 void IDrawableElement.Select(NGSpotlightWindow window, EntryRef key)
 {
     EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(this.path));
 }
Beispiel #15
0
        void IDrawableElement.OnGUI(Rect r, NGSpotlightWindow window, EntryRef k, int i)
        {
            if (SceneDrawer.style == null)
            {
                SceneDrawer.style                  = new GUIStyle(EditorStyles.label);
                SceneDrawer.style.alignment        = TextAnchor.MiddleLeft;
                SceneDrawer.style.padding.left     = 32;
                SceneDrawer.style.fontSize         = 15;
                SceneDrawer.style.richText         = true;
                SceneDrawer.buttonStyle            = new GUIStyle("ButtonLeft");
                SceneDrawer.menuStyle              = new GUIStyle("DropDownButton");
                SceneDrawer.menuStyle.fixedHeight  = NGSpotlightWindow.RowHeight / 1.5F;
                SceneDrawer.menuStyle.padding.left = 0;
                SceneDrawer.menuStyle.margin.left  = 0;
                SceneDrawer.menuStyle.border.left  = 0;
            }

            Rect iconR = r;

            iconR.width = iconR.height;

            GUI.Box(r, "");

            if (Event.current.type == EventType.Repaint)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().hoverSelectionColor : NGSpotlightWindow.HighlightedEntryColor);
                }
                else if (window.selectedEntry == i)
                {
                    Utility.DrawUnfillRect(r, HQ.Settings != null ? HQ.Settings.Get <SpotlightSettings>().outlineSelectionColor : NGSpotlightWindow.SelectedEntryColor);
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                if (i.Equals(DragAndDrop.GetGenericData("i")) == true)
                {
                    DragAndDrop.StartDrag("Drag Asset");
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.MouseDown)
            {
                if (r.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.SetGenericData("i", i);
                    DragAndDrop.objectReferences = new Object[] { AssetDatabase.LoadAssetAtPath <Object>(this.path) };
                }
            }
            else if (Event.current.type == EventType.DragExited)
            {
                DragAndDrop.PrepareStartDrag();
            }

            GUI.DrawTexture(iconR, UtilityResources.UnityIcon, ScaleMode.ScaleToFit);

            if (this.lastChange != window.changeCount)
            {
                this.lastChange            = window.changeCount;
                this.cachedHighlightedName = window.HighlightWeightContent(this.lowerName, this.name, window.cleanLowerKeywords);
            }

            r.width -= SceneDrawer.OpenWidth + SceneDrawer.DropdownWidth;
            GUI.Label(r, this.cachedHighlightedName, SceneDrawer.style);

            if ((Event.current.type == EventType.KeyDown && window.selectedEntry == i && Event.current.keyCode == KeyCode.Return) ||
                (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true && i.Equals(DragAndDrop.GetGenericData("i")) == true))
            {
                if (Event.current.type == EventType.MouseUp && r.Contains(Event.current.mousePosition) == true)
                {
                    DragAndDrop.PrepareStartDrag();
                }

                if (window.selectedEntry == i || Event.current.button != 0)
                {
                    NGSpotlightWindow.UseEntry(k);

                    if (Event.current.button == 0)
                    {
                        this.LoadScene(window, this.path, 0);
                    }
                    else
                    {
                        Selection.activeObject = AssetDatabase.LoadAssetAtPath <Object>(this.path);
                    }

                    window.Close();
                }
                else
                {
                    window.SelectEntry(i);
                }

                Event.current.Use();
            }

            r.height = Mathf.Floor(r.height * .66F);
            r.y     += (iconR.height - r.height) * .5F;
            r.x     += r.width;
            r.width  = SceneDrawer.OpenWidth;
            if (GUI.Button(r, "Open", SceneDrawer.buttonStyle) == true)
            {
                this.LoadScene(window, this.path, 0);
            }

            r.x    += r.width;
            r.width = SceneDrawer.DropdownWidth;
            if (GUI.Button(r, "", SceneDrawer.menuStyle) == true)
            {
                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("Load single"), false, this.LoadScene, window);
                menu.AddItem(new GUIContent("Load additive"), false, this.LoadSceneAdditive, window);
                menu.AddItem(new GUIContent("Load additive without loading"), false, this.LoadSceneAdditiveWithoutLoading, window);
                if (AssetDatabase.LoadAssetAtPath(this.path, typeof(Object)) != null)
                {
                    menu.AddItem(new GUIContent("Ping"), false, this.PingScene);
                }

                menu.DropDown(r);
            }
        }
Beispiel #16
0
 void IDrawableElement.Execute(NGSpotlightWindow window, EntryRef key)
 {
     NGSpotlightWindow.UseEntry(key);
     EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <Object>(this.path));
     this.LoadScene(window, this.path, 0);
 }