diff options
Diffstat (limited to 'Assets/Scripts/Unit/Component/UnitState.cs')
-rw-r--r-- | Assets/Scripts/Unit/Component/UnitState.cs | 27 |
1 files changed, 15 insertions, 12 deletions
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<EUnitState, ExitStateHandler> m_ExitStateHandlerDic = new Dictionary<EUnitState, ExitStateHandler>();
@@ -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<T>(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
|