public override void OnImportAsset(AssetImportContext ctx) { var assetName = Path.GetFileName(ctx.assetPath).Replace(".layout", ""); var spriteRootPath = EditorUtil.ToUnityPath(Path.Combine(EditorUtil.GetBaumSpritesPath(), assetName)); var fontRootPath = EditorUtil.ToUnityPath(EditorUtil.GetBaumFontsPath()); var creator = new PrefabCreator(spriteRootPath, fontRootPath, ctx.assetPath); var go = creator.Create(); ctx.AddObjectToAsset("main obj", go); ctx.SetMainObject(go); }
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; } var assetPath = SliceSprite(asset); AssetDatabase.ImportAsset(assetPath); changed = true; } if (changed) { Debug.Log("AssetDatabase.Refresh();"); 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(); // sh専用処理 var saveDirectoryPath = Path.Combine(Application.dataPath, "Asset Bundles", $"Baum UI {name}"); Directory.CreateDirectory(saveDirectoryPath); var savePath = EditorUtil.ToUnityPath(Path.Combine(saveDirectoryPath, 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)); } }; }