diff options
author | chai <chaifix@163.com> | 2020-10-29 19:39:42 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-10-29 19:39:42 +0800 |
commit | bdf47cf0fd36a5c858575a805cca70ab623868eb (patch) | |
tree | c93691007f656380decbcb93690292e273d4e217 /Assets/Scripts/Avatar/AbilitySystem.cs | |
parent | 61fbc2cdd8368505c3c8ce893af020463cc2a669 (diff) |
*misc
Diffstat (limited to 'Assets/Scripts/Avatar/AbilitySystem.cs')
-rw-r--r-- | Assets/Scripts/Avatar/AbilitySystem.cs | 90 |
1 files changed, 90 insertions, 0 deletions
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; + +/// <summary> +/// 每个角色拥有一个ablity system +/// </summary> +public class AbilitySystem +{ + private static List<AbilitySystem> AbilitySystems = new List<AbilitySystem>(); + + /// <summary> + /// 当前执行的ability + /// </summary> + private AbilityBase m_Currrent; + + public AbilityBase Current + { + get + { + return m_Currrent; + } + } + + private List<AbilityBase> m_Abilities = new List<AbilityBase>(); + + 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 |