From bdf47cf0fd36a5c858575a805cca70ab623868eb Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 29 Oct 2020 19:39:42 +0800 Subject: *misc --- Assets/Scripts/Avatar/AbilitySystem.cs | 90 ++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Assets/Scripts/Avatar/AbilitySystem.cs (limited to 'Assets/Scripts/Avatar/AbilitySystem.cs') diff --git a/Assets/Scripts/Avatar/AbilitySystem.cs b/Assets/Scripts/Avatar/AbilitySystem.cs new file mode 100644 index 00000000..46156c55 --- /dev/null +++ b/Assets/Scripts/Avatar/AbilitySystem.cs @@ -0,0 +1,90 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// 每个角色拥有一个ablity system +/// +public class AbilitySystem +{ + private static List AbilitySystems = new List(); + + /// + /// 当前执行的ability + /// + private AbilityBase m_Currrent; + + public AbilityBase Current + { + get + { + return m_Currrent; + } + } + + private List m_Abilities = new List(); + + public AbilitySystem() + { + AbilitySystems.Add(this); + } + + public static void Update() + { + foreach(var systems in AbilitySystems) + { + systems.OnUpdate(); + } + } + + public static void LateUpdate() + { + foreach (var systems in AbilitySystems) + { + systems.OnLateUpdate(); + } + } + + public void ForceStart(AbilityBase ability) + { + if (ability == null) + return; + + if (m_Currrent != null) + m_Currrent.OnExit(); + + m_Currrent = ability; + m_Currrent.OnEnter(); + } + + public void AddAbility(AbilityBase ability) + { + m_Abilities.Add(ability); + } + + public void OnUpdate() + { + if(m_Currrent != null) + { + m_Currrent.OnUpdate(); + } + } + + public void OnLateUpdate() + { + if(m_Currrent != null) + { + m_Currrent.OnLateUpdate(); + } + } + + + public void SwitchToAbility(AbilityBase targetAbility) + { + if (m_Currrent != null) + m_Currrent.OnExit(); + m_Currrent = targetAbility; + m_Currrent.OnEnter(); + } + +} \ No newline at end of file -- cgit v1.1-26-g67d0