From 4c362271f502b9999cd77e991271f16993d5c665 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 2 Aug 2021 18:58:01 +0800 Subject: *mics --- Assets/Scripts/Unit/Component/UnitState.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'Assets/Scripts/Unit/Component/UnitState.cs') diff --git a/Assets/Scripts/Unit/Component/UnitState.cs b/Assets/Scripts/Unit/Component/UnitState.cs index 500096d3..587c2f33 100644 --- a/Assets/Scripts/Unit/Component/UnitState.cs +++ b/Assets/Scripts/Unit/Component/UnitState.cs @@ -1,4 +1,6 @@ -using System.Collections; +using System; +using System.Reflection; +using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -34,7 +36,6 @@ public class UnitState : UnitComponent public EUnitState CurrentState { get { return m_State; } } private delegate void ExitStateHandler(EUnitState nextState); - private delegate void EnterStateHandler(EUnitState prevState); private Dictionary m_ExitStateHandlerDic = new Dictionary(); @@ -71,10 +72,6 @@ public class UnitState : UnitComponent void InitState() { - m_ExitStateHandlerDic.Add(EUnitState.Idle, OnIdleExit); - m_ExitStateHandlerDic.Add(EUnitState.Move, OnMoveExit); - m_ExitStateHandlerDic.Add(EUnitState.Skill, OnSkillExit); - m_ExitStateHandlerDic.Add(EUnitState.Jump, OnJumpExit); } public void ChangeState(EUnitState nextState, T param = default, bool bForce = false) @@ -87,11 +84,17 @@ public class UnitState : UnitComponent StopAllCoroutines(); EUnitState prevState = m_State; - if (m_ExitStateHandlerDic.ContainsKey(m_State)) - { - m_ExitStateHandlerDic[m_State](nextState); - } - m_State = nextState; + string methodFunc = "On" + m_State.ToString() + "Exit"; + MethodInfo exitMethod = GetType().GetMethod(methodFunc, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(EUnitState) }, null); + if(exitMethod != null) + { + exitMethod.Invoke(this, new object[] { nextState }); + } + else + { + LogHelper.LogError("缺少 " + methodFunc); + } + m_State = nextState; StartCoroutine(m_State.ToString(), param); } @@ -113,7 +116,7 @@ public class UnitState : UnitComponent void OnIdleExit(EUnitState nextState) { - + LogHelper.Log(nextState.ToString()); } #endregion -- cgit v1.1-26-g67d0