summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Component/MonsterState.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit/Component/MonsterState.cs')
-rw-r--r--Assets/Scripts/Unit/Component/MonsterState.cs101
1 files changed, 101 insertions, 0 deletions
diff --git a/Assets/Scripts/Unit/Component/MonsterState.cs b/Assets/Scripts/Unit/Component/MonsterState.cs
new file mode 100644
index 00000000..2beba0d5
--- /dev/null
+++ b/Assets/Scripts/Unit/Component/MonsterState.cs
@@ -0,0 +1,101 @@
+using System;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class MonsterState : UnitState
+{
+ public enum EUnitState
+ {
+ Nien,
+
+ Idle,
+
+ Move,
+
+ HitAir,
+ HitGround,
+ HitFall,
+ KnockDown,
+ Rise,
+
+ Pull,
+ Landing,
+ }
+
+ [SerializeField] private EUnitState m_State;
+ public EUnitState CurrentState { get { return m_State; } }
+
+ UnitAnimation unitAnimation { get { return m_Owner.unitAnimation; } }
+
+ public override void Initialize()
+ {
+ base.Initialize();
+ }
+
+ public void ChangeState<T>(EUnitState nextState, T param = default, bool bForce = false)
+ {
+ if (!IsChange(nextState, bForce))
+ return;
+
+ LogHelper.Log("Monster UnitState: " + m_State.ToString() + " -> " + nextState.ToString());
+
+ StopAllCoroutines();
+
+ EUnitState prevState = m_State;
+ 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);
+ }
+
+ bool IsChange(EUnitState newState, bool bForce)
+ {
+ if (newState != m_State || bForce)
+ return true;
+ return false;
+ }
+
+ IEnumerator Nein() { yield break; }
+ void OnNienExit(EUnitState nextState) { }
+
+ public struct IdleParam { }
+
+ public struct LandingParam { }
+
+ #region Idle
+
+ IEnumerator Idle(IdleParam param)
+ {
+ if (m_Owner.isInAir) // 浮空切换到landing
+ {
+ ChangeState(EUnitState.Landing, new LandingParam());
+ }
+ else // idle
+ {
+ m_Owner.SetYPosition(0);
+ m_Owner.monsterAnimation.AnimIdle();
+ while (true)
+ {
+ yield return null;
+ }
+ }
+ }
+
+ void OnIdleExit(EUnitState nextState)
+ {
+ }
+ #endregion
+
+
+} \ No newline at end of file