summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Avatar/StateSystem.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-11-16 08:30:54 +0800
committerchai <chaifix@163.com>2020-11-16 08:30:54 +0800
commitf325841eff10ae492ce6c634d4b07cf058a068c6 (patch)
tree980d81a4b87d571fcb893fc44f8809af97466bca /Assets/Scripts/Avatar/StateSystem.cs
parentbe3ca8b172f22ce7c4c4316745e0df05de58b069 (diff)
*state system
Diffstat (limited to 'Assets/Scripts/Avatar/StateSystem.cs')
-rw-r--r--Assets/Scripts/Avatar/StateSystem.cs106
1 files changed, 106 insertions, 0 deletions
diff --git a/Assets/Scripts/Avatar/StateSystem.cs b/Assets/Scripts/Avatar/StateSystem.cs
new file mode 100644
index 00000000..42e35445
--- /dev/null
+++ b/Assets/Scripts/Avatar/StateSystem.cs
@@ -0,0 +1,106 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+/// <summary>
+/// 每个角色拥有一个state system
+/// </summary>
+public class StateSystem
+{
+ /// <summary>
+ /// 当前执行的state
+ /// </summary>
+ private StateBase m_Currrent;
+
+ public StateBase Current
+ {
+ get
+ {
+ return m_Currrent;
+ }
+ }
+
+ private List<StateBase> m_States = new List<StateBase>();
+
+ private UberState m_UberState;
+
+ public StateSystem()
+ {
+ }
+
+ public void ForceStart(StateBase state)
+ {
+ if (state == null)
+ return;
+
+ if (m_Currrent != null)
+ m_Currrent.OnExit();
+
+ m_Currrent = state;
+ m_Currrent.OnEnter();
+ }
+
+ public void SetUberState(UberState state)
+ {
+ m_UberState = state;
+ }
+
+ public void AddState(StateBase state)
+ {
+ m_States.Add(state);
+ }
+
+ public void OnUpdate()
+ {
+ if(m_Currrent != null)
+ {
+ m_Currrent.OnUpdate();
+ }
+ if(m_UberState != null)
+ {
+ m_UberState.OnUpdate();
+ }
+ }
+
+ public void OnPhysicsUpdate()
+ {
+ if(m_Currrent != null)
+ {
+ m_Currrent.OnPhysicsUpdate();
+ }
+ if(m_UberState != null)
+ {
+ m_UberState.OnPhysicsUpdate();
+ }
+ }
+
+ public void OnHit(HitInfo info)
+ {
+ if (m_Currrent != null)
+ m_Currrent.OnHit(info);
+ }
+
+ public void OnHurt(HurtInfo info)
+ {
+ if (m_Currrent != null)
+ m_Currrent.OnHurt(info);
+ }
+
+ public void SwitchToState(StateBase targetState)
+ {
+ if (m_Currrent != null)
+ m_Currrent.OnExit();
+ m_Currrent = targetState;
+ m_Currrent.OnEnter();
+ }
+
+ // 获得当前击打如果有的话
+ public Hit GetHit()
+ {
+ if (Current == null || !(Current is AttackState))
+ return null;
+ AttackState state = Current as AttackState;
+ return state.GetHit();
+ }
+
+} \ No newline at end of file