static Texture2D FetchPreview(SearchItem item, SearchContext context, Vector2 size, FetchPreviewOptions options)
    {
        var obj = ObjectFromItem(item);

        if (obj == null)
        {
            return(item.thumbnail);
        }

        var assetPath = SearchUtils.GetHierarchyAssetPath(obj, true);

        if (String.IsNullOrEmpty(assetPath))
        {
            return(item.thumbnail);
        }
        return(AssetPreview.GetAssetPreview(obj) ?? GetAssetPreviewFromPath(assetPath, size, options));
    }
示例#2
0
        public static IEnumerable <SearchAction> CreateActionHandlers(string providerId)
        {
            return(new SearchAction[]
            {
                new SearchAction(providerId, "select", null, "Select object(s) in scene...")
                {
                    execute = (items) =>
                    {
                        FrameObjects(items.Select(i => i.provider.toObject(i, typeof(GameObject))).Where(i => i).ToArray());
                    }
                },

                new SearchAction(providerId, "open", null, "Select containing asset")
                {
                    handler = (item) =>
                    {
                        var pingedObject = PingItem(item);
                        if (pingedObject != null)
                        {
                            var go = pingedObject as GameObject;
                            var assetPath = SearchUtils.GetHierarchyAssetPath(go);
                            if (!String.IsNullOrEmpty(assetPath))
                            {
                                Utils.FrameAssetFromPath(assetPath);
                            }
                            else
                            {
                                FrameObject(go);
                            }
                        }
                    }
                },

                new SearchAction(providerId, "show", null, "Show selected object(s)")
                {
                    enabled = (items) => IsHidden(items),
                    execute = (items) => SceneVisibilityManager.instance.Show(items.Select(i => i.ToObject <GameObject>()).Where(i => i).ToArray(), true)
                },

                new SearchAction(providerId, "hide", null, "Hide selected object(s)")
                {
                    enabled = (items) => !IsHidden(items),
                    execute = (items) => SceneVisibilityManager.instance.Hide(items.Select(i => i.ToObject <GameObject>()).Where(i => i).ToArray(), true)
                },
            });
        }
示例#3
0
        public static IEnumerable <SearchAction> CreateActionHandlers(string providerId)
        {
            return(new SearchAction[]
            {
                new SearchAction(providerId, "select", null, "Select object in scene...")
                {
                    handler = (item, context) =>
                    {
                        var pingedObject = PingItem(item);
                        if (pingedObject != null)
                        {
                            FrameObject(pingedObject);
                        }
                    }
                },

                new SearchAction(providerId, "open", null, "Open containing asset...")
                {
                    handler = (item, context) =>
                    {
                        var pingedObject = PingItem(item);
                        if (pingedObject != null)
                        {
                            var go = pingedObject as GameObject;
                            var assetPath = SearchUtils.GetHierarchyAssetPath(go);
                            if (!String.IsNullOrEmpty(assetPath))
                            {
                                Utils.FrameAssetFromPath(assetPath);
                            }
                            else
                            {
                                FrameObject(go);
                            }
                        }
                    }
                }
            });
        }
示例#4
0
        public SceneProvider(string providerId, string filterId, string displayName)
            : base(providerId, displayName)
        {
            priority           = 50;
            this.filterId      = filterId;
            this.showDetails   = true;
            showDetailsOptions = ShowDetailsOptions.Inspector;

            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;
        }