예제 #1
0
        private static string FetchDescription(SearchItem item)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }

            var go = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid) as GameObject;

            if (go)
            {
                return(item.description = $"Source: {SearchUtils.GetHierarchyPath(go)}");
            }

            var sourceAssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(item.description = $"Source: {GetAssetDescription(sourceAssetPath)}");
        }
예제 #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;
            showDetails        = true;
            showDetailsOptions = ShowDetailsOptions.Inspector | ShowDetailsOptions.Actions | ShowDetailsOptions.Preview | ShowDetailsOptions.DefaultGroup;

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

            SearchMonitor.sceneChanged         += InvalidateScene;
            SearchMonitor.documentsInvalidated += Refresh;

            SearchMonitor.objectChanged += OnObjectChanged;

            supportsSyncViewSearch = true;

            toObject = (item, type) => ObjectFromItem(item, type);
            toKey    = (item) => ToKey(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 == null || context.searchView == null || context.searchView.displayMode == DisplayMode.List)
                {
                    var transformPath = SearchUtils.GetTransformPath(go.transform);
                    if (item.options.HasAny(SearchItemOptions.Compacted))
                    {
                        item.label = transformPath;
                    }
                    else
                    {
                        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})";
                        }
                    }

                    if (context != null)
                    {
                        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) =>
            {
                if (context.selection.Count > 1)
                {
                    Utils.StartDrag(context.selection.Select(i => ObjectFromItem(i)).ToArray(), item.GetLabel(context, true));
                }
                else
                {
                    Utils.StartDrag(new[] { ObjectFromItem(item) }, item.GetLabel(context, true));
                }
            };

            fetchPropositions = (context, options) =>
            {
                if (options.HasAny(SearchPropositionFlags.QueryBuilder))
                {
                    return(FetchQueryBuilderPropositions(context));
                }
                return(m_SceneQueryEngine == null ? new SearchProposition[0] : m_SceneQueryEngine.FindPropositions(context, options));
            };

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

            fetchColumns = (context, items) => SceneSelectors.Enumerate(items);
        }
예제 #4
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;
        }
    static string FetchDescription(SearchItem item, SearchContext context)
    {
        var go = ObjectFromItem(item);

        return(item.description = SearchUtils.GetHierarchyPath(go));
    }