diff options
Diffstat (limited to 'Assets/Scripts/Test 1/TestErika.cs')
-rw-r--r-- | Assets/Scripts/Test 1/TestErika.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Assets/Scripts/Test 1/TestErika.cs b/Assets/Scripts/Test 1/TestErika.cs new file mode 100644 index 00000000..c76f09e0 --- /dev/null +++ b/Assets/Scripts/Test 1/TestErika.cs @@ -0,0 +1,60 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +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.SetParent(unitController.transform); + + Init(); + + } + + private void Init() + { + UnitController unitCtr = unitController.GetOrAddComponent<UnitController>(); + unitCtr.Initialize(unit); + + 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()); + + //unitCtr.unitRootMotion.SetUpRootMotion(unitFolder, actionData); + + } + +} |