Exemplo n.º 1
0
        private static IEnumerator SearchAssets(SearchContext context, List <SearchItem> items, SearchProvider provider)
        {
            var searchQuery    = context.searchQuery;
            var searchGuids    = context.categories.Any(c => c.id == "guid" && c.isEnabled);
            var searchPackages = context.categories.Any(c => c.id == "packages" && c.isEnabled);

            // Search by GUIDs
            if (searchGuids)
            {
                var gui2Path = AssetDatabase.GUIDToAssetPath(searchQuery);
                if (!String.IsNullOrEmpty(gui2Path))
                {
                    yield return(provider.CreateItem(gui2Path, -1, $"{Path.GetFileName(gui2Path)} ({searchQuery})", null, null, null));
                }
            }

            var fileIndexerReady = fileIndexer.IsReady();

            if (fileIndexerReady)
            {
                if (searchQuery.IndexOfAny(k_InvalidIndexedChars) == -1)
                {
                    foreach (var item in SearchFileIndex(searchQuery, searchPackages, provider))
                    {
                        yield return(item);
                    }
                    if (!context.wantsMore)
                    {
                        yield break;
                    }
                }
            }

            if (!searchPackages)
            {
                if (!searchQuery.Contains("a:assets"))
                {
                    searchQuery = "a:assets " + searchQuery;
                }
            }

            foreach (var assetEntry in AssetDatabase.FindAssets(searchQuery).Select(AssetDatabase.GUIDToAssetPath).Select(path => provider.CreateItem(path, Path.GetFileName(path))))
            {
                yield return(assetEntry);
            }

            if (!fileIndexerReady)
            {
                // Indicate to the user that we are still building the index.
                while (!fileIndexer.IsReady())
                {
                    yield return(null);
                }

                foreach (var item in SearchFileIndex(searchQuery, searchPackages, provider))
                {
                    yield return(item);
                }
            }

            // Search file system wildcards
            if (context.searchQuery.Contains('*'))
            {
                var safeFilter   = string.Join("_", context.searchQuery.Split(k_InvalidSearchFileChars));
                var projectFiles = System.IO.Directory.EnumerateFiles(Application.dataPath, safeFilter, System.IO.SearchOption.AllDirectories);
                projectFiles = projectFiles.Select(path => path.Replace(Application.dataPath, "Assets").Replace("\\", "/"));
                foreach (var fileEntry in projectFiles.Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                {
                    yield return(fileEntry);
                }
            }
        }
Exemplo n.º 2
0
        private static IEnumerator SearchAssets(SearchContext context, List <SearchItem> items, SearchProvider provider)
        {
            var searchQuery    = context.searchQuery;
            var searchGuids    = context.categories.Any(c => c.id == "guid" && c.isEnabled);
            var searchPackages = context.categories.Any(c => c.id == "packages" && c.isEnabled);

            // Search by GUIDs
            if (searchGuids)
            {
                var gui2Path = AssetDatabase.GUIDToAssetPath(searchQuery);
                if (!String.IsNullOrEmpty(gui2Path))
                {
                    yield return(provider.CreateItem(gui2Path, -1, $"{Path.GetFileName(gui2Path)} ({searchQuery})", null, null, null));
                }
            }

            if (SearchSettings.useUberIndexing)
            {
                var adbIndex = ADBIndex.Get();

                if (!adbIndex.IsReady())
                {
                    foreach (var assetEntry in AssetDatabase.FindAssets(searchQuery)
                             .Select(AssetDatabase.GUIDToAssetPath)
                             .Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                    {
                        yield return(assetEntry);
                    }
                }

                // Search index
                while (!adbIndex.IsReady())
                {
                    yield return(null);
                }

                yield return(adbIndex.Search(searchQuery).Select(e =>
                {
                    var filename = Path.GetFileName(e.path);
                    var filenameNoExt = Path.GetFileNameWithoutExtension(e.path);
                    var itemScore = e.score;
                    var words = context.searchPhrase;
                    if (filenameNoExt.Equals(words, StringComparison.OrdinalIgnoreCase))
                    {
                        itemScore = SearchProvider.k_RecentUserScore + 1;
                    }

                    string description = adbIndex.GetDebugIndexStrings(e.path);
                    return provider.CreateItem(e.path, itemScore, filename, description, null, null);
                }));
            }
            else
            {
                var fileIndexerReady = fileIndexer.IsReady();
                if (fileIndexerReady)
                {
                    if (searchQuery.IndexOfAny(k_InvalidIndexedChars) == -1)
                    {
                        foreach (var item in SearchFileIndex(searchQuery, searchPackages, provider))
                        {
                            yield return(item);
                        }
                        if (!context.wantsMore)
                        {
                            yield break;
                        }
                    }
                }

                if (!searchPackages)
                {
                    if (!searchQuery.Contains("a:assets"))
                    {
                        searchQuery = "a:assets " + searchQuery;
                    }
                }

                foreach (var assetEntry in AssetDatabase.FindAssets(searchQuery).Select(AssetDatabase.GUIDToAssetPath).Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                {
                    yield return(assetEntry);
                }

                if (!fileIndexerReady)
                {
                    // Indicate to the user that we are still building the index.
                    while (!fileIndexer.IsReady())
                    {
                        yield return(null);
                    }

                    foreach (var item in SearchFileIndex(searchQuery, searchPackages, provider))
                    {
                        yield return(item);
                    }
                }
            }

            // Search file system wildcards
            if (context.searchQuery.Contains('*'))
            {
                var safeFilter   = string.Join("_", context.searchQuery.Split(k_InvalidSearchFileChars));
                var projectFiles = System.IO.Directory.EnumerateFiles(Application.dataPath, safeFilter, System.IO.SearchOption.AllDirectories);
                projectFiles = projectFiles.Select(path => path.Replace(Application.dataPath, "Assets").Replace("\\", "/"));
                foreach (var fileEntry in projectFiles.Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                {
                    yield return(fileEntry);
                }
            }
        }
Exemplo n.º 3
0
        private static IEnumerator SearchAssets(SearchContext context, SearchProvider provider)
        {
            var        searchQuery    = context.searchQuery;
            const bool searchGuids    = true;
            const bool searchPackages = true;

            // Search by GUIDs
            if (searchGuids)
            {
                var gui2Path = AssetDatabase.GUIDToAssetPath(searchQuery);
                if (!String.IsNullOrEmpty(gui2Path))
                {
                    yield return(provider.CreateItem(gui2Path, -1, $"{Path.GetFileName(gui2Path)} ({searchQuery})", null, null, null));
                }
            }

            if (SearchSettings.assetIndexing == SearchAssetIndexing.Complete)
            {
                yield return(assetIndexes.Select(db => SearchIndexes(context, provider, db.index)));
            }
            else if (SearchSettings.assetIndexing == SearchAssetIndexing.Files)
            {
                if (searchQuery.IndexOf(':') != -1)
                {
                    foreach (var assetEntry in AssetDatabase.FindAssets(searchQuery)
                             .Select(AssetDatabase.GUIDToAssetPath)
                             .Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                    {
                        yield return(assetEntry);
                    }
                }

                while (!fileIndexer.IsReady())
                {
                    yield return(null);
                }

                foreach (var item in SearchFiles(searchQuery, searchPackages, provider))
                {
                    yield return(item);
                }
            }
            else
            {
                foreach (var assetEntry in AssetDatabase.FindAssets(searchQuery).Select(AssetDatabase.GUIDToAssetPath).Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                {
                    yield return(assetEntry);
                }
            }

            if (context.wantsMore && context.filterType != null && String.IsNullOrEmpty(context.searchQuery))
            {
                yield return(AssetDatabase.FindAssets($"t:{context.filterType.Name}")
                             .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
                             .Select(path => provider.CreateItem(path, 999, Path.GetFileName(path), null, null, null)));
            }

            // Search file system wild cards
            if (context.searchQuery.Contains('*'))
            {
                var safeFilter   = string.Join("_", context.searchQuery.Split(k_InvalidSearchFileChars));
                var projectFiles = System.IO.Directory.EnumerateFiles(Application.dataPath, safeFilter, System.IO.SearchOption.AllDirectories);
                projectFiles = projectFiles.Select(path => path.Replace(Application.dataPath, "Assets").Replace("\\", "/"));
                foreach (var fileEntry in projectFiles.Select(path => provider.CreateItem(path, Path.GetFileName(path))))
                {
                    yield return(fileEntry);
                }
            }
        }