Files
AIGame/AIClient/AgentScripts/BuildBattleSkills.cs
T

70 lines
5.8 KiB
C#

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<BattleSkillPresentation>();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<GameObject>(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<list.arraySize;n++){var go=(GameObject)PrefabUtility.InstantiatePrefab(prefab,root.transform);list.GetArrayElementAtIndex(n).objectReferenceValue=go.GetComponent<ParticleSystem>();}
}
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<Sounds.Length;i++)
{
string path="Assets/Bundles/Sound/SFX/BattleSkills/Sfx_"+Sounds[i]+".wav";AssetDatabase.ImportAsset(path,ImportAssetOptions.ForceUpdate);var importer=(AudioImporter)AssetImporter.GetAtPath(path);if(importer==null)throw new Exception("Missing "+path);var sample=importer.defaultSampleSettings;sample.compressionFormat=AudioCompressionFormat.PCM;sample.loadType=AudioClipLoadType.DecompressOnLoad;sample.sampleRateSetting=AudioSampleRateSetting.PreserveSampleRate;importer.defaultSampleSettings=sample;importer.forceToMono=false;importer.SaveAndReimport();clips.GetArrayElementAtIndex(i).objectReferenceValue=AssetDatabase.LoadAssetAtPath<AudioClip>(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<AudioSource>();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<actors.Length;i++)
{
string path="../Config/Art/"+(team==0&&i!=0?"Companions":"EnemyCharacters")+"/"+actors[i]+".json";
var recipe=JObject.Parse(File.ReadAllText(path));impacts.GetArrayElementAtIndex(i).floatValue=(float)recipe["attackImpact"];
}
}
so.ApplyModifiedPropertiesWithoutUndo();foreach(var t in root.GetComponentsInChildren<Transform>(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<BattleSkillPresentation>(true);if(old!=null)Object.DestroyImmediate(old.gameObject);PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath<GameObject>(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";
}
}