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); })); }
public override void OnImportAsset(AssetImportContext ctx) { var settings = new SearchDatabase.Settings { guid = null, root = null, roots = null, source = null, name = null, baseScore = 0, excludes = null, includes = null, type = type, options = GetOptions(), }; EditorApplication.LockReloadAssemblies(); try { var indexer = SearchDatabase.CreateIndexer(settings); indexer.IndexDocument(ctx.assetPath, false); indexer.ApplyUnsorted(); var indexArtifactPath = ctx.GetResultPath($"{type}.{(int)options:X}.index".ToLowerInvariant()); using (var fileStream = new FileStream(indexArtifactPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read)) indexer.Write(fileStream); Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, $"\nGenerated {type} ({GetType().Name}) {indexArtifactPath} for {ctx.assetPath} with {options}"); ctx.DependsOnSourceAsset(Path.GetDirectoryName(ctx.assetPath).Replace("\\", "/")); ctx.DependsOnCustomDependency(GetType().GUID.ToString("N")); #if UNITY_2020_1_OR_NEWER ctx.DependsOnCustomDependency(nameof(CustomObjectIndexerAttribute)); #endif } catch (Exception ex) { Debug.LogException(ex); ctx.LogImportError(ex.Message); } finally { EditorApplication.UnlockReloadAssemblies(); } }
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; db.settings.root = Path.GetDirectoryName(filePath).Replace("\\", "/"); if (String.IsNullOrEmpty(db.settings.name)) { db.settings.name = fileName; } db.index = db.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); } }
internal static void SendIndexLoaded(SearchDatabase sb) { indexLoaded?.Invoke(sb); }
internal void OnEnable() { m_DB = (SearchDatabase)target; m_Settings = serializedObject.FindProperty("settings"); m_Settings.isExpanded = true; }
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)})"); }