using System; using System.IO; using System.Linq; using HotUpdate.Gameplay; using Newtonsoft.Json.Linq; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.SceneManagement; using Object=UnityEngine.Object; public static class BuildBattleSkills { public const string Bank="Assets/Bundles/Combat/BattleSkillPresentation.prefab"; const string Arena="Assets/Bundles/Scenes/Prototype/PrototypeArena.prefab"; static readonly string[] Pets={"RockBall","FireCat","BudBud","SparkBird","BubbleTurtle","RockRhino","FlameLion","VineSprite","ThunderLeopard","TideWhale"}; static readonly string[] Enemies={"Hornlet","Dashlet","Shellhorn","HornCaptain","GreatHorn"}; static readonly string[] Effects={"FireCharge","Fireball","FireHit","RockHit","Shield"}; static readonly string[] Sounds={"FireCharge","FireLaunch","FireHit","RockHit","Shield","Heal","Slow","Lightning","EnemyHit"}; public static string Build() { if(EditorApplication.isPlaying)throw new Exception("Author in Edit Mode"); var previous=SceneManager.GetActiveScene();var scene=EditorSceneManager.NewScene(NewSceneSetup.EmptyScene,NewSceneMode.Additive); try { var plan=JObject.Parse(File.ReadAllText("../Config/Combat/partner_presentations_v1.json")); SceneManager.SetActiveScene(scene);var root=new GameObject("BattleSkillPresentation");var player=root.AddComponent();var so=new SerializedObject(player);var effects=so.FindProperty("_effects");effects.arraySize=15; var ground=so.FindProperty("_groundEffects");ground.arraySize=15;var lifetimes=so.FindProperty("_effectLifetimes");lifetimes.arraySize=15; for(int i=0;i<15;i++) { JToken definition=i>=5?plan["effects"][i-5]:null;var list=effects.GetArrayElementAtIndex(i).FindPropertyRelative("instances");list.arraySize=i<5?(i==1?12:6):(int)definition["poolSize"]; var path=i<5?"Assets/Bundles/Combat/SkillSlice/Vfx_Skill_"+Effects[i]+".prefab":(string)definition["path"];var prefab=AssetDatabase.LoadAssetAtPath(path);if(prefab==null)throw new Exception("Missing "+path); ground.GetArrayElementAtIndex(i).boolValue=definition!=null&&(bool)definition["ground"];lifetimes.GetArrayElementAtIndex(i).floatValue=definition==null?.65f:(float)definition["lifetime"]; for(int n=0;n();} } var profiles=so.FindProperty("_profiles");profiles.arraySize=10; for(int i=0;i<10;i++)foreach(var property in ((JObject)plan["profiles"][i]).Properties())if(property.Name!="actor")profiles.GetArrayElementAtIndex(i).FindPropertyRelative(property.Name).intValue=(int)property.Value; var clips=so.FindProperty("_clips");clips.arraySize=Sounds.Length; for(int i=0;i(path); } var voices=so.FindProperty("_voices");voices.arraySize=8; for(int i=0;i<8;i++){var go=new GameObject("Voice"+i);go.transform.SetParent(root.transform,false);var voice=go.AddComponent();voice.playOnAwake=false;voice.spatialBlend=0;voice.volume=.3f/8;voices.GetArrayElementAtIndex(i).objectReferenceValue=voice;} for(int team=0;team<2;team++) { var actors=team==0?Pets:Enemies;var impacts=so.FindProperty(team==0?"_petImpacts":"_enemyImpacts");impacts.arraySize=actors.Length; for(int i=0;i(true))t.gameObject.layer=30;PrefabUtility.SaveAsPrefabAsset(root,Bank);Object.DestroyImmediate(root); } finally{SceneManager.SetActiveScene(previous);EditorSceneManager.CloseScene(scene,true);} var arena=PrefabUtility.LoadPrefabContents(Arena); try { foreach(string group in new[]{"Heroes","Enemies"})foreach(Transform actor in arena.transform.Find(group)) { var muzzle=actor.Find("SkillMuzzle");if(muzzle==null){muzzle=new GameObject("SkillMuzzle").transform;muzzle.SetParent(actor,false);muzzle.localPosition=new Vector3(0,group=="Heroes"?.85f:.8f,-.48f);muzzle.gameObject.layer=30;} } var old=arena.GetComponentInChildren(true);if(old!=null)Object.DestroyImmediate(old.gameObject);PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath(Bank),arena.transform);PrefabUtility.SaveAsPrefabAsset(arena,Arena); } finally{PrefabUtility.UnloadPrefabContents(arena);} return "Saved bounded battle skill bank, authored animation phases for 10 pets / 5 enemies, attached to existing arena"; } }