From fee35151213939d61d2dbd9d6a0ba71ac93b91cf Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 17 Oct 2020 15:39:34 +0800 Subject: =?UTF-8?q?+=20=E8=BF=9E=E5=87=BB=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbilitySystem/Abilities/AttackAbility.cs | 65 ++++++++++++++++++++-- .../Scripts/AbilitySystem/Abilities/IdleAbility.cs | 22 +++++--- .../Scripts/AbilitySystem/Abilities/MoveAbility.cs | 22 ++++++-- 3 files changed, 91 insertions(+), 18 deletions(-) (limited to 'Assets/Scripts/AbilitySystem/Abilities') diff --git a/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs b/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs index 6732cf57..067d49a8 100644 --- a/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs +++ b/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs @@ -2,12 +2,67 @@ using System.Collections.Generic; using UnityEngine; -/// -/// 单个招式ability -/// -public class AttackAbilityBase : AbilityBase +public class AttackAbility : AbilityBase { - // 攻击ability默认都会回到idle + Animator m_Animator; + int m_AnimHash; + /// + /// 在跑动状态时可以切换的ability + /// + private List m_Triggers = new List(); + + public AttackAbility(Animator animator, int animation) + { + m_Animator = animator; + m_AnimHash = animation; + } + + public override void OnInit() + { + + } + + public override void OnDefend() + { + throw new System.NotImplementedException(); + } + + public override void OnEnter() + { + m_Animator.CrossFade(m_AnimHash, 0); + } + + public override void OnExit() + { + } + + public override void OnHit() + { + } + + public override void OnHurt() + { + } + + public override void OnTranslate(AbilityBase to) + { + } + + public override void OnUpdate() + { + foreach (var abilityTrigger in m_Triggers) + { + if (abilityTrigger.Update()) + break; + } + } + + public void AddTrigger(Trigger trigger) + { + if (trigger == null || m_Triggers.Contains(trigger)) + return; + m_Triggers.Add(trigger); + } } diff --git a/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs b/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs index 4b9cd21e..8be58188 100644 --- a/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs +++ b/Assets/Scripts/AbilitySystem/Abilities/IdleAbility.cs @@ -5,25 +5,27 @@ using UnityEngine; public class IdleAbility : AbilityBase { - /// - /// idle的动画 - /// + Animator m_Animator; + int m_AnimHash; /// /// 在Idle状态时可以切换的ability /// - private List m_Triggers; + private List m_Triggers = new List(); - public IdleAbility(int animation) + public IdleAbility(Animator animator, int animation) : base() { - m_AnimHash = animation; + m_Animator = animator; + m_AnimHash = animation; } public override void OnEnter() { - + m_Animator.speed = 1; + m_Animator.CrossFade(m_AnimHash, 0.3f); + m_Animator.speed = 0; } public override void OnInit() @@ -42,9 +44,11 @@ public class IdleAbility : AbilityBase base.OnUpdate(); } - public void AddTrigger() + public void AddTrigger(Trigger trigger) { - + if (trigger == null || m_Triggers.Contains(trigger)) + return; + m_Triggers.Add(trigger); } } diff --git a/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs b/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs index 2c39afd5..eadee433 100644 --- a/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs +++ b/Assets/Scripts/AbilitySystem/Abilities/MoveAbility.cs @@ -4,11 +4,19 @@ using UnityEngine; public class MoveAbility : AbilityBase { + Animator m_Animator; + int m_AnimHash; /// /// 在跑动状态时可以切换的ability /// - private List m_Triggers; + private List m_Triggers = new List(); + + public MoveAbility(Animator animator, int animation) + { + m_Animator = animator; + m_AnimHash = animation; + } public override void OnInit() { @@ -22,7 +30,7 @@ public class MoveAbility : AbilityBase public override void OnEnter() { - + m_Animator.CrossFade(m_AnimHash, 0); } public override void OnExit() @@ -31,7 +39,6 @@ public class MoveAbility : AbilityBase public override void OnHit() { - throw new System.NotImplementedException(); } public override void OnHurt() @@ -40,7 +47,6 @@ public class MoveAbility : AbilityBase public override void OnTranslate(AbilityBase to) { - throw new System.NotImplementedException(); } public override void OnUpdate() @@ -51,4 +57,12 @@ public class MoveAbility : AbilityBase break; } } + + public void AddTrigger(Trigger trigger) + { + if (trigger == null || m_Triggers.Contains(trigger)) + return; + m_Triggers.Add(trigger); + } + } -- cgit v1.1-26-g67d0