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/Abilities/AttackAbility.cs | 143 +++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Assets/Scripts/Avatar/Abilities/AttackAbility.cs (limited to 'Assets/Scripts/Avatar/Abilities/AttackAbility.cs') diff --git a/Assets/Scripts/Avatar/Abilities/AttackAbility.cs b/Assets/Scripts/Avatar/Abilities/AttackAbility.cs new file mode 100644 index 00000000..9ca52a4c --- /dev/null +++ b/Assets/Scripts/Avatar/Abilities/AttackAbility.cs @@ -0,0 +1,143 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public struct AttackAbilityConfig +{ + public Vector3 velocity; // velocity setup + public int motion; + public Animator animator; + public PhysicsBody body; +} + +// 单独的一个招式 +public class AttackAbility : AbilityBase +{ + AttackAbilityConfig m_Config = new AttackAbilityConfig(); + + /// + /// 在跑动状态时可以切换的ability + /// + private List m_Triggers = new List(); + + private List m_LateTriggers = new List(); + + /// + /// 这个招式所有hit的效果 + /// + public HitDefination[] HitDef; + + /// + /// 从动画结束开始计时 + /// + float m_TimeCount; + public float ExpireTime + { + get + { + return m_TimeCount; + } + } + + /// + /// 这个招式的hit个数 + /// + public int HitCount + { + get + { + return HitDef != null ? HitDef.Length : 0; + } + } + + + public AttackAbility(Animator animator, int animation, PhysicsBody body = null) + { + m_Config.animator = animator; + m_Config.motion = animation; + m_Config.velocity = Vector3.zero; + m_Config.body = body; + } + + public AttackAbility(AttackAbilityConfig config) + { + m_Config = config; + } + + public override void OnInit() + { + } + + public override void OnDefend() + { + throw new System.NotImplementedException(); + } + + public override void OnEnter() + { + m_TimeCount = 0; + + m_Config.animator.CrossFade(m_Config.motion, 0); + + if(m_Config.body != null) + { + m_Config.body.LocalVelocity = m_Config.velocity; + } + } + + public override void OnExit() + { + m_TimeCount = 0; + } + + public override void OnHit() + { + } + + public override void OnHurt() + { + } + + public override void OnTranslate(AbilityBase to) + { + } + + public override void OnUpdate() + { + AnimatorStateInfo info = m_Config.animator.GetCurrentAnimatorStateInfo(0); + if(info.shortNameHash == m_Config.motion && info.normalizedTime >= 0.99f) + { + m_TimeCount += Time.deltaTime; + } + foreach (var abilityTrigger in m_Triggers) + { + if (abilityTrigger.Update() && abilityTrigger.Swallow) + break; + } + } + + // 在物理模拟之后 + public override void OnLateUpdate() + { + foreach (var trigger in m_LateTriggers) + { + if (trigger.Update() && trigger.Swallow) + break; + } + } + + public void AddTrigger(Trigger trigger) + { + if (trigger == null || m_Triggers.Contains(trigger)) + return; + m_Triggers.Add(trigger); + } + + public void AddLateTrigger(Trigger trigger) + { + if (trigger == null || m_LateTriggers.Contains(trigger)) + return; + m_LateTriggers.Add(trigger); + } + +} -- cgit v1.1-26-g67d0