From ce73a13f28e5a947df8f1f87f1f1be20010952ec Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 2 Aug 2021 08:35:26 +0800 Subject: =?UTF-8?q?*=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Test 1/TestErika.cs | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Assets/Scripts/Test 1/TestErika.cs (limited to 'Assets/Scripts/Test 1/TestErika.cs') 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(); + unitCtr.Initialize(unit); + + UnitRootMotion unitRootMotion = unitCtr.unitRootMotion; + + RootMotionProxy rootMotionProxy = unit.GetOrAddComponent(); + + Animator animator = unit.GetComponent(); + 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); + + } + +} -- cgit v1.1-26-g67d0