From 01f06fb513dab303abeb02d7e1007e397874bcc0 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 16 Nov 2020 21:08:39 +0800 Subject: *misc --- Assets/Scripts/Avatar/StateController.cs | 106 +++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Assets/Scripts/Avatar/StateController.cs (limited to 'Assets/Scripts/Avatar/StateController.cs') diff --git a/Assets/Scripts/Avatar/StateController.cs b/Assets/Scripts/Avatar/StateController.cs new file mode 100644 index 00000000..12ba6fe4 --- /dev/null +++ b/Assets/Scripts/Avatar/StateController.cs @@ -0,0 +1,106 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// 每个角色拥有一个state system +/// +public class StateController +{ + /// + /// 当前执行的state + /// + private StateBase m_Currrent; + + public StateBase Current + { + get + { + return m_Currrent; + } + } + + private List m_States = new List(); + + private UberState m_UberState; + + public StateController() + { + } + + 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 -- cgit v1.1-26-g67d0