public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { var changed = false; // Create Directory foreach (var asset in importedAssets) { if (!asset.Contains(EditorUtil.ImportDirectoryPath)) { continue; } if (!string.IsNullOrEmpty(Path.GetExtension(asset))) { continue; } CreateSpritesDirectory(asset); changed = true; } // Slice Sprite foreach (var asset in importedAssets) { if (!asset.Contains(EditorUtil.ImportDirectoryPath)) { continue; } if (!asset.EndsWith(".png", System.StringComparison.Ordinal)) { continue; } SliceSprite(asset); changed = true; } if (changed) { AssetDatabase.Refresh(); } EditorApplication.delayCall += () => { // Delete Directory foreach (var asset in importedAssets) { if (!asset.Contains(EditorUtil.ImportDirectoryPath)) { continue; } if (!string.IsNullOrEmpty(Path.GetExtension(asset))) { continue; } Debug.LogFormat("[Baum2] Delete Directory: {0}", EditorUtil.ToUnityPath(asset)); AssetDatabase.DeleteAsset(EditorUtil.ToUnityPath(asset)); changed = true; } // Create Prefab foreach (var asset in importedAssets) { if (!asset.Contains(EditorUtil.ImportDirectoryPath)) { continue; } if (!asset.EndsWith(".layout.txt", System.StringComparison.Ordinal)) { continue; } var name = Path.GetFileName(asset).Replace(".layout.txt", ""); var spriteRootPath = EditorUtil.ToUnityPath(Path.Combine(EditorUtil.GetBaumSpritesPath(), name)); var fontRootPath = EditorUtil.ToUnityPath(EditorUtil.GetBaumFontsPath()); var creator = new PrefabCreator(spriteRootPath, fontRootPath, asset); var go = creator.Create(); var savePath = EditorUtil.ToUnityPath(Path.Combine(EditorUtil.GetBaumPrefabsPath(), name + ".prefab")); #if UNITY_2018_3_OR_NEWER PrefabUtility.SaveAsPrefabAsset(go, savePath); #else Object originalPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(savePath); if (originalPrefab == null) { originalPrefab = PrefabUtility.CreateEmptyPrefab(savePath); } PrefabUtility.ReplacePrefab(go, originalPrefab, ReplacePrefabOptions.ReplaceNameBased); #endif GameObject.DestroyImmediate(go); Debug.LogFormat("[Baum2] Create Prefab: {0}", savePath); AssetDatabase.DeleteAsset(EditorUtil.ToUnityPath(asset)); } }; }