summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Component/UnitState.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-08-02 18:58:01 +0800
committerchai <chaifix@163.com>2021-08-02 18:58:01 +0800
commit4c362271f502b9999cd77e991271f16993d5c665 (patch)
tree7f4d1291457fafa54f06b59ff34c8fb6db9e0954 /Assets/Scripts/Unit/Component/UnitState.cs
parent4f7fa7c6d5db44179b21dc17da0f7322efc4cb45 (diff)
*mics
Diffstat (limited to 'Assets/Scripts/Unit/Component/UnitState.cs')
-rw-r--r--Assets/Scripts/Unit/Component/UnitState.cs27
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