public override void OnInspectorGUI() { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("AnimeList", (string)null, GUILayout.MaxWidth(60)); if (GUILayout.Button("Pickup")) { Undo.RegisterUndo(_target, "Pickup"); // trim _target.CleanupAnimeList(); // find all anims attached to sprites in scene var sprites = FindObjectsOfType(typeof(SsSprite)) as SsSprite[]; foreach (var e in sprites) { SsAnimation anm = e.Animation; if (!anm) { continue; } _target.AddAnime(anm); } } if (GUILayout.Button("Add")) { Undo.RegisterUndo(_target, "Add"); _target.animeList.Add(null); } if (GUILayout.Button("Clear")) { Undo.RegisterUndo(_target, "Clear"); _target.animeList.Clear(); } if (PrefabUtility.GetPrefabType(_target) == PrefabType.Prefab || PrefabUtility.GetPrefabType(_target) == PrefabType.PrefabInstance) { if (GUILayout.Button("Instantiate")) { var obj = Instantiate(_target); Undo.RegisterCreatedObjectUndo(obj, "Instantiate"); obj.name = SsAssetDatabase.fileName; } } } EditorGUILayout.EndHorizontal(); DrawDefaultInspector(); }
OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { // reject re-entering for files unnecessary to import during an another file is created internally. if (_s_rejectReenter) { // Debug.LogError("REJECT ->" + importedAssets[0]); return; } string dbFilename = Path.GetFileName(SsAssetDatabase.filePath); // ignore database import if (importedAssets.Length == 1 && importedAssets[0].EndsWith(dbFilename, _pathComparison)) { #if _RELINK_DB_OBJECT_TO_PREFAB UpdateDatabaseObjectInHierarchy(); #endif // Debug.LogWarning("IGNORE Database"); return; } // if (importedAssets.Length > 0) // Debug.Log("ENTER importing " + importedAssets[0] + " count: " + importedAssets.Length); // reject reenter this function while importing new generated files. _s_rejectReenter = true; try { AssetDatabase.Refresh(); // get game object contains database GameObject databaseGo = GetDatabaseGo(); bool createDatabase = false; // make database first to assure the existing. if (databaseGo == null) { createDatabase = true; } else { // ignore database delete and re-create it if (deletedAssets.Length > 0 && deletedAssets[0].EndsWith(dbFilename, _pathComparison)) { createDatabase = true; } } if (createDatabase) { // create database // Debug.LogWarning("Create Database: " + databaseGo); var go = CreateDatabaseGo(); RebuildDatabase(go); databaseGo = SaveDatabase(go); } _database = databaseGo.GetComponent <SsAssetDatabase>(); int prevAnimeListCount = _database.animeList.Count; // filter imported files and create assets as needed foreach (var name in importedAssets) { // ignore database file in filename list if (name.EndsWith(dbFilename, _pathComparison)) { continue; } #if _GENERATE_SHADERS if (name.EndsWith(_shaderTemplateFilename, _pathComparison)) { BuildShaders(name); } #endif if (name.EndsWith(".ssax", _pathComparison)) { SsaxImporter v = SsaxImporter.Create(name); if (v != null) { var anm = v.AnimeRes; CreateSpritePrefab(anm); _database.AddAnime(anm); } } } // assets will be deleted foreach (var name in deletedAssets) { if (!name.EndsWith(".asset", _pathComparison)) { continue; } Object asset = AssetDatabase.LoadAssetAtPath(name, typeof(SsAnimation)); // remove animation element from list SsAnimation anim = asset as SsAnimation; if (anim == null) { continue; } _database.animeList.Remove(anim); } // cleanup null elements in the database _database.CleanupAnimeList(); if (_database.animeList.Count != prevAnimeListCount) { // apply modification of database to actual file EditorUtility.SetDirty(databaseGo); } AssetDatabase.SaveAssets(); #if _RELINK_DB_OBJECT_TO_PREFAB // update game object refers to the database prefab UpdateDatabaseObjectInHierarchy(); #endif } catch { // Debug.LogWarning("ABORT importing"); throw; } finally { _s_rejectReenter = false; // Debug.Log("LEAVE importing"); } }