static void BuildIndex(ImageDatabase idb) { try { var assetPaths = AssetDatabase.FindAssets("t:texture2d").Select(AssetDatabase.GUIDToAssetPath); var textures = assetPaths.Select(path => AssetDatabase.LoadMainAssetAtPath(path) as Texture2D).Where(t => t); var current = 1; var total = textures.Count(); foreach (var assetPath in assetPaths) { var texture = AssetDatabase.LoadMainAssetAtPath(assetPath) as Texture2D; if (texture == null) { continue; } ReportProgress(texture.name, current / (float)total, false, idb); idb.IndexTexture(assetPath, texture); ++current; } idb.WriteBytes(); ReportProgress("Indexing Finished", 1.0f, true, idb); } catch (Exception e) { Console.WriteLine(e); ReportProgress("Indexing failed", 1.0f, true, idb); } }
static void ReportProgress(string description, float progress, bool finished, ImageDatabase idb) { EditorUtility.DisplayProgressBar($"Building {idb.name} index...", description, progress); if (finished) { EditorUtility.ClearProgressBar(); } }