From f325841eff10ae492ce6c634d4b07cf058a068c6 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 16 Nov 2020 08:30:54 +0800 Subject: *state system --- Assets/Scripts/Avatar/Abilities/AttackAbility.cs | 175 ----------------------- 1 file changed, 175 deletions(-) delete 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 deleted file mode 100644 index 6e7c503f..00000000 --- a/Assets/Scripts/Avatar/Abilities/AttackAbility.cs +++ /dev/null @@ -1,175 +0,0 @@ -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(); - - private List m_Triggers = new List(); - - private List m_PhysicsTriggers = new List(); - - /// - /// 这个招式配置的hit - /// - private List m_Hits = new List(); - - /// - /// 从动画结束开始计时 - /// - float m_TimeCount; - public float ExpireTime - { - get - { - return m_TimeCount; - } - } - - /// - /// 这个招式的hit个数 - /// - public int HitCount - { - get - { - return m_Hits != null ? m_Hits.Count : 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; - } - - foreach(var hit in m_Hits) - { - hit.WipeRecords(); - } - - foreach(var trigger in m_Triggers) - { - trigger.Reset(); - } - } - - public override void OnExit() - { - m_TimeCount = 0; - } - - public override void OnHit(HitInfo info) - { - } - - public override void OnHurt(HurtInfo info) - { - } - - 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 OnPhysicsUpdate() - { - foreach (var trigger in m_PhysicsTriggers) - { - 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 AddPhysicsTrigger(Trigger trigger) - { - if (trigger == null || m_PhysicsTriggers.Contains(trigger)) - return; - m_PhysicsTriggers.Add(trigger); - } - - public void AddHitDefination(HitDefination defination) - { - Hit info = new Hit(); - info.defination = defination; - m_Hits.Add(info); - } - - // 获得当前时间点产生的hit - public Hit GetHit() - { - AnimatorStateInfo info = m_Config.animator.GetCurrentAnimatorStateInfo(0); - float normalizeTime = info.normalizedTime; - for (int i = 0; i< m_Hits.Count; ++i) - { - Hit hit = m_Hits[i]; - float start = hit.defination.start; - float end = hit.defination.end; - if(normalizeTime >= start && normalizeTime <= end) - { - return hit; - } - } - return null; - } - -} -- cgit v1.1-26-g67d0