示例#1
0
 private static void TrackAssetIndexChanges(string[] updated, string[] deleted, string[] moved)
 {
     if (updated.Concat(deleted).Any(u => u.EndsWith(".index", StringComparison.OrdinalIgnoreCase)))
     {
         assetIndexes = SearchDatabase.Enumerate("asset").ToList();
     }
 }
示例#2
0
        private static void TrackAssetIndexChanges(string[] updated, string[] deleted, string[] moved)
        {
            updated = updated.Where(u => u.EndsWith(".index", StringComparison.OrdinalIgnoreCase)).ToArray();
            deleted = deleted.Where(u => u.EndsWith(".index", StringComparison.OrdinalIgnoreCase)).ToArray();
            var loaded = assetIndexes != null?assetIndexes.Select(db => AssetDatabase.GetAssetPath(db)).ToArray() : new string[0];

            if (updated.Except(loaded).Count() > 0 || loaded.Intersect(deleted).Count() > 0)
            {
                assetIndexes = SearchDatabase.Enumerate("asset").ToList();
            }
        }
示例#3
0
 private bool Reimport(string assetPath)
 {
     if (!SearchDatabase.incrementalIndexCache.TryGetValue(assetPath, out var cachedIndexBytes))
     {
         return(false);
     }
     SearchDatabase.incrementalIndexCache.Remove(assetPath);
     db.bytes = cachedIndexBytes;
     return(db.index.LoadBytes(cachedIndexBytes, (loaded) =>
     {
         db.Log($"Reimport.{loaded}");
         SearchDatabase.SendIndexLoaded(db);
     }));
 }
示例#4
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var filePath = ctx.assetPath;
            var jsonText = System.IO.File.ReadAllText(filePath);
            var settings = JsonUtility.FromJson <SearchDatabase.Settings>(jsonText);
            var fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);

            hideFlags |= HideFlags.HideInInspector;

            #if DEBUG_INDEXING
            using (new DebugTimer($"Importing index {fileName}"))
            #endif
            {
                db           = ScriptableObject.CreateInstance <SearchDatabase>();
                db.name      = fileName;
                db.hideFlags = HideFlags.NotEditable;
                db.settings  = settings;
                if (String.IsNullOrEmpty(db.settings.path))
                {
                    db.settings.path = filePath;
                }
                if (String.IsNullOrEmpty(db.settings.name))
                {
                    db.settings.name = fileName;
                }
                db.index = SearchDatabase.CreateIndexer(settings);

                if (!Reimport(filePath))
                {
                    if (ShouldDelayImport())
                    {
                        db.Log("Delayed Import");
                        EditorApplication.delayCall += () => AssetDatabase.ImportAsset(filePath);
                    }
                    else
                    {
                        Build();
                    }
                }

                ctx.AddObjectToAsset(fileName, db);
                ctx.SetMainObject(db);
            }
        }
示例#5
0
 private static void UpdateObjectIndexes()
 {
     m_ObjectIndexes = SearchDatabase.Enumerate("scene", "prefab").ToList();
 }
示例#6
0
        private static IEnumerator SearchIndexes(string searchQuery, SearchContext context, SearchProvider provider, SearchDatabase db, int scoreModifier = 0)
        {
            while (db.index == null)
            {
                yield return(null);
            }

            // Search index
            var index = db.index;

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

            yield return(index.Search(searchQuery.ToLowerInvariant()).Select(e =>
            {
                var itemScore = e.score + scoreModifier;
                return provider.CreateItem(context, e.id, itemScore, null, null, null, index.GetDocument(e.index));
            }));
        }
示例#7
0
        private static IEnumerator SearchIndexes(string searchQuery, SearchContext context, SearchProvider provider, SearchDatabase db)
        {
            while (!db.ready)
            {
                if (!db || context.options.HasFlag(SearchFlags.Synchronous))
                {
                    yield break;
                }
                yield return(null);
            }

            // Search index
            var index = db.index;

            db.Report("Search", searchQuery);
            yield return(index.Search(searchQuery.ToLowerInvariant()).Select(e => CreateItem(context, provider, db.name, e.id, e.score)));
        }
示例#8
0
 internal void OnEnable()
 {
     m_DB              = (SearchDatabase)target;
     m_Settings        = serializedObject.FindProperty("settings");
     m_IndexTitleLabel = new GUIContent($"{m_DB.index?.name ?? m_DB.name} ({EditorUtility.FormatBytes(m_DB.bytes?.Length ?? 0)})");
 }