コード例 #1
0
ファイル: AssetProvider.cs プロジェクト: Yuceldd/2d-platform
        private static void TrackAssetIndexChanges(string[] updated, string[] deleted, string[] moved)
        {
            var loaded = assetIndexes?.Where(db => db).Select(db => AssetDatabase.GetAssetPath(db)).ToArray() ?? new string[0];

            if (FilterIndexes(updated).Except(loaded).Count() > 0 || loaded.Intersect(FilterIndexes(deleted)).Count() > 0)
            {
                reloadAssetIndexes = true;
            }

            FindProvider.Update(updated, deleted, moved);
        }
コード例 #2
0
        private static IEnumerator SearchAssets(SearchContext context, SearchProvider provider)
        {
            var searchQuery = context.searchQuery;
            var useIndexing = !context.options.HasFlag(SearchFlags.NoIndexing);

            if (!string.IsNullOrEmpty(searchQuery))
            {
                // Search by GUID
                var guidPath = AssetDatabase.GUIDToAssetPath(searchQuery);
                if (!string.IsNullOrEmpty(guidPath))
                {
                    yield return(provider.CreateItem(context, guidPath, -1, $"{Path.GetFileName(guidPath)} ({searchQuery})", null, null, null));
                }

                // Search indexes that are ready
                if (useIndexing)
                {
                    foreach (var db in assetIndexes.Where(db => db.ready))
                    {
                        yield return(SearchIndexes(context.searchQuery, context, provider, db));
                    }
                }

                // Perform a quick search on asset paths
                var findOptions = FindOptions.Words | FindOptions.Regex | FindOptions.Glob | (context.wantsMore ? FindOptions.Fuzzy : FindOptions.None);
                foreach (var e in FindProvider.Search(context, findOptions))
                {
                    yield return(CreateItem(context, provider, "Find", e.path, 998 + e.score));
                }

                // Finally wait for indexes that are being built to end the search.
                if (useIndexing && !context.options.HasFlag(SearchFlags.Synchronous))
                {
                    foreach (var db in assetIndexes.Where(db => !db.ready))
                    {
                        yield return(SearchIndexes(context.searchQuery, context, provider, db));
                    }
                }
            }

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

                if (assetIndexes != null)
                {
                    yield return(assetIndexes.Select(db => SearchIndexes($"has={context.filterType.Name}", context, provider, db)));
                }
            }
        }