コード例 #1
0
ファイル: SceneProvider.cs プロジェクト: Buster-00/Q_G
        private IEnumerator SearchItems(SearchContext context, SearchProvider provider)
        {
            if (!String.IsNullOrEmpty(context.searchQuery))
            {
                if (m_HierarchyChanged)
                {
                    m_GameObjects      = fetchGameObjects();
                    m_SceneQueryEngine = new SceneQueryEngine(m_GameObjects);
                    m_HierarchyChanged = false;
                }

                yield return(m_SceneQueryEngine.Search(context).Select(gameObject =>
                {
                    if (!gameObject)
                    {
                        return null;
                    }
                    return AddResult(context, provider, gameObject.GetInstanceID().ToString(), 0, false);
                }));
            }
            else if (context.wantsMore && context.filterType != null && String.IsNullOrEmpty(context.searchQuery))
            {
                yield return(GameObject.FindObjectsOfType(context.filterType)
                             .Select(obj =>
                {
                    if (obj is Component c)
                    {
                        return c.gameObject;
                    }
                    return obj as GameObject;
                })
                             .Where(go => go)
                             .Select(go => AddResult(context, provider, go.GetInstanceID().ToString(), 999, false)));
            }
        }
コード例 #2
0
        public SceneProvider(string providerId, string filterId, string displayName)
            : base(providerId, displayName)
        {
            priority           = 50;
            this.filterId      = filterId;
            this.showDetails   = true;
            showDetailsOptions = ShowDetailsOptions.Inspector | ShowDetailsOptions.Actions;

            isEnabledForContextualSearch = () =>
                                           Utils.IsFocusedWindowTypeName("SceneView") ||
                                           Utils.IsFocusedWindowTypeName("SceneHierarchyWindow");

            EditorApplication.hierarchyChanged += () => m_HierarchyChanged = true;

            onEnable = () =>
            {
                if (m_HierarchyChanged)
                {
                    m_GameObjects      = fetchGameObjects();
                    m_SceneQueryEngine = new SceneQueryEngine(m_GameObjects);
                    m_HierarchyChanged = false;
                }
            };

            onDisable = () =>
            {
                // Only track changes that occurs when Quick Search is not active.
                m_HierarchyChanged = false;
            };

            toObject = (item, type) => ObjectFromItem(item);

            fetchItems = (context, items, provider) => SearchItems(context, provider);

            fetchLabel = (item, context) =>
            {
                if (item.label != null)
                {
                    return(item.label);
                }

                var go = ObjectFromItem(item);
                if (!go)
                {
                    return(item.id);
                }

                if (context.searchView == null || context.searchView.displayMode == DisplayMode.List)
                {
                    var transformPath = SearchUtils.GetTransformPath(go.transform);
                    var components    = go.GetComponents <Component>();
                    if (components.Length > 2 && components[1] && components[components.Length - 1])
                    {
                        item.label = $"{transformPath} ({components[1].GetType().Name}..{components[components.Length - 1].GetType().Name})";
                    }
                    else if (components.Length > 1 && components[1])
                    {
                        item.label = $"{transformPath} ({components[1].GetType().Name})";
                    }
                    else
                    {
                        item.label = $"{transformPath} ({item.id})";
                    }

                    long       score   = 1;
                    List <int> matches = new List <int>();
                    var        sq      = Utils.CleanString(context.searchQuery);
                    if (FuzzySearch.FuzzyMatch(sq, Utils.CleanString(item.label), ref score, matches))
                    {
                        item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches);
                    }
                }
                else
                {
                    item.label = go.name;
                }

                return(item.label);
            };

            fetchDescription = (item, context) =>
            {
                var go = ObjectFromItem(item);
                return(item.description = SearchUtils.GetHierarchyPath(go));
            };

            fetchThumbnail = (item, context) =>
            {
                var obj = ObjectFromItem(item);
                if (obj == null)
                {
                    return(null);
                }

                return(item.thumbnail = Utils.GetThumbnailForGameObject(obj));
            };

            fetchPreview = (item, context, size, options) =>
            {
                var obj = ObjectFromItem(item);
                if (obj == null)
                {
                    return(item.thumbnail);
                }
                return(Utils.GetSceneObjectPreview(obj, size, options, item.thumbnail));
            };

            startDrag = (item, context) =>
            {
                Utils.StartDrag(context.selection.Select(i => ObjectFromItem(i)).ToArray(), item.GetLabel(context, true));
            };

            trackSelection = (item, context) => PingItem(item);

            fetchGameObjects       = SceneQueryEngine.FetchGameObjects;
            buildKeywordComponents = SceneQueryEngine.BuildKeywordComponents;
        }
コード例 #3
0
        public SceneProvider(string providerId, string filterId, string displayName)
            : base(providerId, displayName)
        {
            priority      = 50;
            this.filterId = filterId;

            isEnabledForContextualSearch = () =>
                                           Utils.IsFocusedWindowTypeName("SceneView") ||
                                           Utils.IsFocusedWindowTypeName("SceneHierarchyWindow");

            EditorApplication.hierarchyChanged += () => m_HierarchyChanged = true;

            onEnable = () =>
            {
                if (m_HierarchyChanged)
                {
                    m_GameObjects      = fetchGameObjects();
                    m_SceneQueryEngine = new SceneQueryEngine(m_GameObjects);
                    m_HierarchyChanged = false;
                }
            };

            onDisable = () =>
            {
                // Only track changes that occurs when Quick Search is not active.
                m_HierarchyChanged = false;
            };

            toObject = (item, type) => ObjectFromItem(item);

            fetchItems = (context, items, provider) => SearchItems(context, provider);

            fetchLabel = (item, context) =>
            {
                if (item.label != null)
                {
                    return(item.label);
                }

                var go = ObjectFromItem(item);
                if (!go)
                {
                    return(item.id);
                }

                if (context.searchView == null || context.searchView.displayMode == DisplayMode.List)
                {
                    var transformPath = SearchUtils.GetTransformPath(go.transform);
                    var components    = go.GetComponents <Component>();
                    if (components.Length > 2 && components[1] && components[components.Length - 1])
                    {
                        item.label = $"{transformPath} ({components[1].GetType().Name}..{components[components.Length - 1].GetType().Name})";
                    }
                    else if (components.Length > 1 && components[1])
                    {
                        item.label = $"{transformPath} ({components[1].GetType().Name})";
                    }
                    else
                    {
                        item.label = $"{transformPath} ({item.id})";
                    }

                    long       score   = 1;
                    List <int> matches = new List <int>();
                    var        sq      = Utils.CleanString(context.searchQuery);
                    if (FuzzySearch.FuzzyMatch(sq, Utils.CleanString(item.label), ref score, matches))
                    {
                        item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches);
                    }
                }
                else
                {
                    item.label = go.name;
                }

                return(item.label);
            };

            fetchDescription = (item, context) =>
            {
                var go = ObjectFromItem(item);
                return(item.description = SearchUtils.GetHierarchyPath(go));
            };

            fetchThumbnail = (item, context) =>
            {
                var obj = ObjectFromItem(item);
                if (obj == null)
                {
                    return(null);
                }

                return(item.thumbnail = Utils.GetThumbnailForGameObject(obj));
            };

            fetchPreview = (item, context, size, options) =>
            {
                var obj = ObjectFromItem(item);
                if (obj == null)
                {
                    return(item.thumbnail);
                }

                var sr = obj.GetComponent <SpriteRenderer>();
                if (sr && sr.sprite && sr.sprite.texture)
                {
                    return(sr.sprite.texture);
                }

                #if PACKAGE_UGUI
                var uii = obj.GetComponent <UnityEngine.UI.Image>();
                if (uii && uii.mainTexture is Texture2D uiit)
                {
                    return(uiit);
                }
                #endif

                var preview = AssetPreview.GetAssetPreview(obj);
                if (preview)
                {
                    return(preview);
                }

                var assetPath = SearchUtils.GetHierarchyAssetPath(obj, true);
                if (String.IsNullOrEmpty(assetPath))
                {
                    return(item.thumbnail);
                }
                return(Utils.GetAssetPreviewFromPath(assetPath, size, options));
            };

            startDrag = (item, context) =>
            {
                var obj = ObjectFromItem(item);
                if (obj != null)
                {
                    Utils.StartDrag(obj, item.label);
                }
            };

            trackSelection = (item, context) => PingItem(item);

            fetchGameObjects       = SceneQueryEngine.FetchGameObjects;
            buildKeywordComponents = SceneQueryEngine.BuildKeywordComponents;
        }