diff options
Diffstat (limited to 'Assets/Scripts/Test 1')
-rw-r--r-- | Assets/Scripts/Test 1/TestErika.cs | 136 |
1 files changed, 82 insertions, 54 deletions
diff --git a/Assets/Scripts/Test 1/TestErika.cs b/Assets/Scripts/Test 1/TestErika.cs index f6f9ba0e..967c3bdb 100644 --- a/Assets/Scripts/Test 1/TestErika.cs +++ b/Assets/Scripts/Test 1/TestErika.cs @@ -1,62 +1,90 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; +[Serializable] +public class UnitSetUp
+{
+ public UnitActionData actionData; // 动作配置
+
+ public GameObject unitControllerPrefab;
+
+ public GameObject unitPrefab;
+
+ public RuntimeAnimatorController animController;
+
+ public string unitFolder;
+
+ [HideInInspector]
+ public GameObject unit;
+
+ [HideInInspector]
+ public GameObject unitController; +} + public class TestErika : MonoBehaviour { - public UnitActionData actionData; // 动作配置 - - public GameObject unitControllerPrefab; - - public GameObject unitPrefab; - - public RuntimeAnimatorController animController; - - public string unitFolder; - - [HideInInspector] - public GameObject unit; - - [HideInInspector] - public GameObject unitController; - - private void Awake() - { - unitController = GameObject.Instantiate(unitControllerPrefab); - unitController.transform.position = Vector3.zero; - unitController.transform.rotation = Quaternion.identity; - - unit = GameObject.Instantiate(unitPrefab); - unit.transform.rotation = Quaternion.Euler(0, 90, 0); - unit.transform.SetParent(unitController.transform); - - Init(); - - } - - private void Init() + public UnitSetUp erika; + public UnitSetUp monster;
+
+ private void Awake() { - UnitController unitCtr = unitController.GetOrAddComponent<UnitController>(); - unitCtr.Initialize(unit, "Assets/Bundle/Unit/PC/Erika/"); - - UnitRootMotion unitRootMotion = unitCtr.unitRootMotion; - - RootMotionProxy rootMotionProxy = unit.GetOrAddComponent<RootMotionProxy>(); - - Animator animator = unit.GetComponent<Animator>(); - AnimatorOverrideController animCtr = new AnimatorOverrideController(animController); - animCtr.name = unitPrefab.name + " Override Controller"; - animator.runtimeAnimatorController = animCtr; - - //foreach(var action in actionData.actions) - //{ - // animCtr[action.Key.ToString()] = action.Value; - //} - - unitCtr.unitState.ChangeState(UnitState.EUnitState.Idle, new UnitState.IdleParam(), true); - - //unitCtr.unitRootMotion.SetUpRootMotion(unitFolder, actionData); - - } + SetupErika(); + SetupMonster(); + } + + void SetupErika()
+ {
+ erika.unitController = GameObject.Instantiate(erika.unitControllerPrefab);
+ erika.unitController.transform.position = Vector3.zero;
+ erika.unitController.transform.rotation = Quaternion.identity;
+
+ erika.unit = GameObject.Instantiate(erika.unitPrefab);
+ erika.unit.transform.rotation = Quaternion.Euler(0, 90, 0);
+ erika.unit.transform.SetParent(erika.unitController.transform);
+
+ UnitController unitCtr = erika.unitController.GetOrAddComponent<UnitController>();
+ unitCtr.Initialize(erika.unit, erika.unitFolder);
+
+ UnitRootMotion unitRootMotion = unitCtr.unitRootMotion;
+
+ RootMotionProxy rootMotionProxy = erika.unit.GetOrAddComponent<RootMotionProxy>();
+
+ Animator animator = erika.unit.GetComponent<Animator>();
+ AnimatorOverrideController animCtr = new AnimatorOverrideController(erika.animController);
+ animCtr.name = erika.unitPrefab.name + " Override Controller";
+ animator.runtimeAnimatorController = animCtr;
+
+ unitCtr.pcState.ChangeState(PCState.EUnitState.Idle, new PCState.IdleParam(), true);
+ } + + void SetupMonster()
+ {
+ monster.unitController = GameObject.Instantiate(monster.unitControllerPrefab);
+ monster.unitController.transform.position = Vector3.zero;
+ monster.unitController.transform.rotation = Quaternion.identity;
+
+ monster.unit = GameObject.Instantiate(monster.unitPrefab);
+ monster.unit.transform.rotation = Quaternion.Euler(0, 90, 0);
+ monster.unit.transform.SetParent(monster.unitController.transform);
+
+ UnitController unitCtr = monster.unitController.GetOrAddComponent<UnitController>();
+ unitCtr.Initialize(monster.unit, monster.unitFolder);
+
+ UnitRootMotion unitRootMotion = unitCtr.unitRootMotion;
+
+ RootMotionProxy rootMotionProxy = monster.unit.GetOrAddComponent<RootMotionProxy>();
+
+ Animator animator = monster.unit.GetComponent<Animator>();
+ AnimatorOverrideController animCtr = new AnimatorOverrideController(monster.animController);
+ animCtr.name = monster.unitPrefab.name + " Override Controller";
+ animator.runtimeAnimatorController = animCtr;
+
+ unitCtr.monsterState.ChangeState(MonsterState.EUnitState.Idle, new MonsterState.IdleParam(), true);
+
+ monster.unitController.transform.position = new Vector3(5, 0, 0);
+ monster.unitController.transform.rotation *= Quaternion.Euler(0, 180, 0);
+ } } |