Beispiel #1
0
        private static IEnumerable <SearchItem> FetchItems(SearchContext context, SearchProvider provider)
        {
            // Fetch all editor windows
            foreach (var win in s_AllEditorWindows)
            {
                if (!win)
                {
                    continue;
                }

                // Query the UIElements DOM
                var allElements = win.rootVisualElement.Query("");
                foreach (var element in allElements.ToList())
                {
                    // Check if match
                    if (SearchProvider.MatchSearchGroups(context, GetName(element)) ||
                        SearchProvider.MatchSearchGroups(context, element.tooltip) ||
                        SearchProvider.MatchSearchGroups(context, GetTransformPath(element)) ||
                        (element is TextElement textElement && SearchProvider.MatchSearchGroups(context, textElement.text)))
                    {
                        // Return matching elements
                        var info = new VisualElementInfo {
                            window = win, element = element, hostWindowName = win.titleContent.text
                        };
                        var item = provider.CreateItem($"uie_{element.GetHashCode()}", element.tabIndex, null, null, null, info);
                        item.descriptionFormat |= SearchItemDescriptionFormat.Ellipsis | SearchItemDescriptionFormat.RightToLeft | SearchItemDescriptionFormat.FuzzyHighlight;
                        yield return(item);
                    }
            private static SearchProvider CreateProvider()
            {
                return(new SearchProvider(type, displayName)
                {
                    priority = 85,
                    filterId = "#",
                    isExplicitProvider = true,
                    fetchItems = (context, items, provider) =>
                    {
                        if (!context.searchText.StartsWith(provider.filterId))
                        {
                            return;
                        }

                        // Cache all available static APIs
                        if (methods == null)
                        {
                            methods = FetchStaticAPIMethodInfo();
                        }

                        foreach (var m in methods)
                        {
                            if (!SearchProvider.MatchSearchGroups(context, m.Name))
                            {
                                continue;
                            }

                            var visibilityString = !m.IsPublic ? "<i>Internal</i> - " : String.Empty;
                            items.Add(provider.CreateItem(m.Name, m.IsPublic ? 0 : 1, m.Name, $"{visibilityString}{m.DeclaringType} - {m.ToString()}", null, m));
                        }
                    },

                    fetchThumbnail = (item, context) => Icons.shortcut
                });
            }
            internal static SearchProvider CreateProvider()
            {
                var helpProvider = new SearchProvider(type, displayName)
                {
                    priority           = -1,
                    filterId           = "?",
                    isExplicitProvider = true,
                    fetchItems         = (context, items, provider) =>
                    {
                        if (m_StaticItemToAction == null)
                        {
                            BuildHelpItems(provider);
                        }

                        var dynamicItems = GetRecentSearchItems(provider);
                        var helpItems    = m_StaticItemToAction.Keys.Concat(dynamicItems);

                        if (string.IsNullOrEmpty(context.searchQuery) || string.IsNullOrWhiteSpace(context.searchQuery))
                        {
                            items.AddRange(helpItems);
                            return(null);
                        }

                        items.AddRange(helpItems.Where(item => SearchProvider.MatchSearchGroups(context, item.label) || SearchProvider.MatchSearchGroups(context, item.description)));
                        return(null);
                    }
                };

                return(helpProvider);
            }
Beispiel #4
0
            private static IEnumerable <SearchItem> SearchPackages(SearchContext context, SearchProvider provider)
            {
                if (string.IsNullOrEmpty(context.searchQuery))
                {
                    yield break;
                }

                if (s_SearchRequest == null || s_ListRequest == null)
                {
                    yield break;
                }

                while (!s_SearchRequest.IsCompleted || !s_ListRequest.IsCompleted)
                {
                    yield return(null);
                }

                if (s_SearchRequest.Result == null || s_ListRequest.Result == null)
                {
                    yield break;
                }

                foreach (var p in s_SearchRequest.Result)
                {
                    if (p.keywords.Contains(context.searchQuery) ||
                        SearchProvider.MatchSearchGroups(context, p.description.ToLowerInvariant(), true) ||
                        SearchProvider.MatchSearchGroups(context, p.name.ToLowerInvariant(), true))
                    {
                        yield return(provider.CreateItem(p.packageId, String.IsNullOrEmpty(p.resolvedPath) ? 0 : 1, FormatLabel(p), FormatDescription(p), null, p));
                    }
                }
            }
            internal static SearchProvider CreateProvider()
            {
                List <string> shortcuts = new List <string>();

                GetMenuInfo(itemNames, shortcuts);
                itemNamesLower = itemNames.Select(n => n.ToLowerInvariant()).ToArray();

                return(new SearchProvider(type, displayName)
                {
                    priority = 80,
                    filterId = "me:",
                    fetchItems = (context, items, provider) =>
                    {
                        for (int i = 0; i < itemNames.Count; ++i)
                        {
                            var menuName = itemNames[i];
                            if (!SearchProvider.MatchSearchGroups(context, itemNamesLower[i], true))
                            {
                                continue;
                            }
                            items.Add(provider.CreateItem(menuName, Utils.GetNameFromPath(menuName), menuName));
                        }
                    },

                    fetchThumbnail = (item, context) => Icons.shortcut
                });
            }
Beispiel #6
0
            internal static SearchProvider CreateProvider()
            {
                List <string> shortcuts = new List <string>();

                GetMenuInfo(itemNames, shortcuts);
                itemNamesLower = itemNames.Select(n => n.ToLowerInvariant()).ToArray();

                return(new SearchProvider(type, displayName)
                {
                    priority = 80,
                    filterId = "me:",

                    onEnable = () =>
                    {
                        #if UNITY_2019_1_OR_NEWER
                        shortcutIds = ShortcutManager.instance.GetAvailableShortcutIds().ToArray();
                        #else
                        shortcutIds = new string[0];
                        #endif
                    },

                    onDisable = () =>
                    {
                        shortcutIds = new string[0];
                    },

                    fetchItems = (context, items, provider) =>
                    {
                        for (int i = 0; i < itemNames.Count; ++i)
                        {
                            var menuName = itemNames[i];
                            if (!SearchProvider.MatchSearchGroups(context, itemNamesLower[i], true))
                            {
                                continue;
                            }

                            items.Add(provider.CreateItem(menuName, Utils.GetNameFromPath(menuName)));
                        }

                        return null;
                    },

                    fetchDescription = (item, context) =>
                    {
                        if (String.IsNullOrEmpty(item.description))
                        {
                            item.description = GetMenuDescription(item.id);
                        }
                        return item.description;
                    },

                    fetchThumbnail = (item, context) => Icons.shortcut
                });
            }
Beispiel #7
0
            private static SearchItem SearchLogEntry(SearchContext context, SearchProvider provider, LogEntry logEntry)
            {
                if (!SearchProvider.MatchSearchGroups(context, logEntry.msgLowerCased, true))
                {
                    return(null);
                }

                var logItem = provider.CreateItem(logEntry.id, ~logEntry.lineNumber, logEntry.msg, null, null, logEntry);

                logItem.descriptionFormat = SearchItemDescriptionFormat.Ellipsis | SearchItemDescriptionFormat.RightToLeft | SearchItemDescriptionFormat.Highlight;
                return(logItem);
            }
Beispiel #8
0
            private static SearchProvider CreateProvider()
            {
                return(new SearchProvider(type, displayName)
                {
                    filterId = "se:",
                    fetchItems = (context, items, provider) =>
                    {
                        items.AddRange(SettingsPaths.value
                                       .Where(path => SearchProvider.MatchSearchGroups(context, path))
                                       .Select(path => provider.CreateItem(path, null, path)));
                        return null;
                    },

                    fetchLabel = (item, context) => item.label ?? (item.label = Utils.GetNameFromPath(item.id)),

                    fetchThumbnail = (item, context) => Icons.settings
                });
            }
Beispiel #9
0
            internal static SearchProvider CreateProvider()
            {
                if (providers == null)
                {
                    providers = FetchSettingsProviders();
                }

                return(new SearchProvider(type, displayName)
                {
                    filterId = "se:",
                    fetchItems = (context, items, provider) =>
                    {
                        items.AddRange(providers.Where(settings =>
                                                       SearchProvider.MatchSearchGroups(context, settings.settingsPath))
                                       .Select(settings => provider.CreateItem(settings.settingsPath, Utils.GetNameFromPath(settings.settingsPath), settings.settingsPath)));
                    },

                    fetchThumbnail = (item, context) => Icons.settings
                });
            }
Beispiel #10
0
            internal static SearchProvider CreateProvider()
            {
                return(new SearchProvider(type, displayName)
                {
                    priority = 90,
                    filterId = "pkg:",

                    onEnable = () =>
                    {
                        s_ListRequest = UnityEditor.PackageManager.Client.List(true);
                        s_SearchRequest = UnityEditor.PackageManager.Client.SearchAll();
                    },

                    fetchItems = (context, items, provider) =>
                    {
                        if (s_SearchRequest == null || s_ListRequest == null)
                        {
                            return;
                        }

                        if (!s_SearchRequest.IsCompleted || !s_ListRequest.IsCompleted)
                        {
                            return;
                        }

                        if (s_SearchRequest.Result == null || s_ListRequest.Result == null)
                        {
                            return;
                        }

                        items.AddRange(s_SearchRequest.Result
                                       .Where(p => SearchProvider.MatchSearchGroups(context, p.description.ToLowerInvariant(), true) ||
                                              SearchProvider.MatchSearchGroups(context, p.name.ToLowerInvariant(), true) ||
                                              p.keywords.Contains(context.searchQuery))
                                       .Select(p => provider.CreateItem(p.packageId,
                                                                        String.IsNullOrEmpty(p.resolvedPath) ? 0 : 1, FormatLabel(p), FormatDescription(p), null, p)).ToArray());
                    },

                    fetchThumbnail = (item, context) => Icons.settings
                });
            }
Beispiel #11
0
                public SceneSearchProvider(string providerId, string displayName = null)
                    : base(providerId, displayName)
                {
                    priority = 50;
                    filterId = "h:";

                    onEnable = () =>
                    {
                        var objects = UnityEngine.Object.FindObjectsOfType(typeof(GameObject));
                        gods = new GOD[objects.Length];
                        for (int i = 0; i < objects.Length; ++i)
                        {
                            gods[i].gameObject = (GameObject)objects[i];
                            gods[i].name       = gods[i].gameObject.name.ToLower();
                        }
                    };

                    onDisable = () =>
                    {
                        gods = new GOD[0];
                    };

                    fetchItems = (context, items, provider) =>
                    {
                        var sq = context.searchQuery.ToLowerInvariant();

                        int addedCount = 0;
                        int i = 0, end = 0;
                        for (i = 0, end = gods.Length; i != end; ++i)
                        {
                            if (!SearchProvider.MatchSearchGroups(context, gods[i].name, true))
                            {
                                continue;
                            }

                            var go           = gods[i].gameObject;
                            var gameObjectId = go.GetInstanceID().ToString();

                            items.Add(provider.CreateItem(gameObjectId, $"{go.name} ({gameObjectId})", null));
                            if (++addedCount >= 200)
                            {
                                break;
                            }
                        }
                    };

                    fetchDescription = (item, context) =>
                    {
                        const int maxChars = 85;
                        var       go       = ObjectFromItem(item);
                        item.data = item.description = go.transform.GetPath();
                        if (item.description.Length > maxChars)
                        {
                            item.description = "..." + item.description.Substring(item.description.Length - maxChars, maxChars);
                        }
                        return(item.description);
                    };

                    fetchThumbnail = (item, context) =>
                    {
                        if (item.thumbnail)
                        {
                            return(item.thumbnail);
                        }

                        var obj = ObjectFromItem(item);
                        if (obj != null)
                        {
                            item.thumbnail = PrefabUtility.GetIconForGameObject(obj);
                            if (item.thumbnail)
                            {
                                return(item.thumbnail);
                            }
                            item.thumbnail = EditorGUIUtility.ObjectContent(obj, obj.GetType()).image as Texture2D;
                        }

                        return(item.thumbnail);
                    };

                    startDrag = (item, context) =>
                    {
                        var obj = ObjectFromItem(item);
                        if (obj != null)
                        {
                            DragAndDrop.PrepareStartDrag();
                            DragAndDrop.objectReferences = new[] { obj };
                            DragAndDrop.StartDrag("Drag scene object");
                        }
                    };

                    isItemValid = item => ObjectFromItem(item) != null;
                }