Exemple #1
0
        internal static SearchProvider CreateProvider()
        {
            return(new SearchProvider(type, displayName)
            {
                priority = 25,
                filterId = "p:",
                showDetails = SearchSettings.fetchPreview,

                subCategories = new List <NameEntry>()
                {
                    new NameEntry("guid", "guid"),
                    new NameEntry("packages", "packages")
                },

                onEnable = () =>
                {
                    if (!SearchSettings.useUberIndexing && fileIndexer == null)
                    {
                        var packageRoots = Utils.GetPackagesPaths().Select(p => new SearchIndexerRoot(Path.GetFullPath(p).Replace('\\', '/'), p));
                        var roots = new[] { new SearchIndexerRoot(Application.dataPath, "Assets") }.Concat(packageRoots);
                        fileIndexer = new FileSearchIndexer(type, roots);
                        fileIndexer.Build();
                    }
                },

                isEnabledForContextualSearch = () => QuickSearch.IsFocusedWindowTypeName("ProjectBrowser"),

                fetchItems = (context, items, _provider) => SearchAssets(context, items, _provider),

                fetchKeywords = (context, lastToken, items) =>
                {
                    if (!lastToken.StartsWith("t:"))
                    {
                        return;
                    }
                    items.AddRange(typeFilter.Select(t => "t:" + t));
                },

                fetchDescription = (item, context) => (item.description = GetAssetDescription(item.id)),
                fetchThumbnail = (item, context) => Utils.GetAssetThumbnailFromPath(item.id),
                fetchPreview = (item, context, size, options) => Utils.GetAssetPreviewFromPath(item.id, size, options),

                startDrag = (item, context) =>
                {
                    var obj = AssetDatabase.LoadAssetAtPath <Object>(item.id);
                    if (obj == null)
                    {
                        return;
                    }

                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.objectReferences = new[] { obj };
                    DragAndDrop.StartDrag(item.label);
                },
                trackSelection = (item, context) => Utils.PingAsset(item.id)
            });
        }
Exemple #2
0
            private static SearchProvider CreateProjectAssetsProvider()
            {
                var roots = new[] { new SearchIndexer.Root(Application.dataPath, "Assets") }.Concat(GetPackageRoots());
                var fileIndexer = new FileSearchIndexer(k_ProjectAssetsType, roots);

                fileIndexer.Build();

                var provider = CreateProvider(k_ProjectAssetsType, displayName, "p:", 25,
                                              (context, items, _provider) => SearchAssets(context, items, _provider, fileIndexer));

                provider.subCategories.Add(new NameId("guid", "guid"));
                provider.subCategories.Add(new NameId("packages", "packages"));

                return(provider);
            }
 private static void SetupIndexers()
 {
     if (SearchSettings.assetIndexing == SearchAssetIndexing.Files && fileIndexer == null)
     {
         var packageRoots = Utils.GetPackagesPaths().Select(p => new SearchIndexerRoot(Path.GetFullPath(p).Replace('\\', '/'), p));
         var roots = new[] { new SearchIndexerRoot(Application.dataPath, "Assets") }.Concat(packageRoots);
         fileIndexer = new FileSearchIndexer(type, roots);
         fileIndexer.Build();
     }
     else if (SearchSettings.assetIndexing == SearchAssetIndexing.Complete && assetIndexes == null)
     {
         assetIndexes = ADBIndex.Enumerate().ToList();
         foreach (var db in assetIndexes)
         {
             db.IncrementalUpdate();
         }
         AssetPostprocessorIndexer.contentRefreshed += TrackAssetIndexChanges;
     }
 }
Exemple #4
0
        internal static SearchProvider CreateProvider()
        {
            return(new SearchProvider(type, displayName)
            {
                priority = 25,
                filterId = "p:",
                showDetails = SearchSettings.fetchPreview,

                onEnable = () =>
                {
                    if (SearchSettings.assetIndexing == SearchAssetIndexing.Files && fileIndexer == null)
                    {
                        var packageRoots = Utils.GetPackagesPaths().Select(p => new SearchIndexerRoot(Path.GetFullPath(p).Replace('\\', '/'), p));
                        var roots = new[] { new SearchIndexerRoot(Application.dataPath, "Assets") }.Concat(packageRoots);
                        fileIndexer = new FileSearchIndexer(type, roots);
                        fileIndexer.Build();
                    }
                    else if (SearchSettings.assetIndexing == SearchAssetIndexing.Complete && assetIndexes == null)
                    {
                        assetIndexes = ADBIndex.Enumerate().ToList();
                        foreach (var db in assetIndexes)
                        {
                            db.IncrementalUpdate();
                        }
                        AssetPostprocessorIndexer.contentRefreshed += TrackAssetIndexChanges;
                    }
                },

                isEnabledForContextualSearch = () => Utils.IsFocusedWindowTypeName("ProjectBrowser"),

                toObject = (item, type) => AssetDatabase.LoadAssetAtPath(item.id, type),

                fetchItems = (context, items, provider) => SearchAssets(context, provider),

                fetchKeywords = (context, lastToken, items) =>
                {
                    if (!lastToken.Contains(":"))
                    {
                        return;
                    }
                    if (SearchSettings.assetIndexing == SearchAssetIndexing.Complete)
                    {
                        items.AddRange(assetIndexes.SelectMany(db => db.index.GetKeywords()));
                    }
                    else
                    {
                        items.AddRange(typeFilter.Select(t => "t:" + t));
                    }
                },

                fetchDescription = (item, context) => (item.description = GetAssetDescription(item.id)),
                fetchThumbnail = (item, context) => Utils.GetAssetThumbnailFromPath(item.id),
                fetchPreview = (item, context, size, options) => Utils.GetAssetPreviewFromPath(item.id, size, options),

                startDrag = (item, context) =>
                {
                    var obj = AssetDatabase.LoadAssetAtPath <Object>(item.id);
                    if (obj)
                    {
                        Utils.StartDrag(obj, item.label);
                    }
                },
                trackSelection = (item, context) => Utils.PingAsset(item.id)
            });
        }