summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Avatar/Abilities/AttackAbility.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-29 19:39:42 +0800
committerchai <chaifix@163.com>2020-10-29 19:39:42 +0800
commitbdf47cf0fd36a5c858575a805cca70ab623868eb (patch)
treec93691007f656380decbcb93690292e273d4e217 /Assets/Scripts/Avatar/Abilities/AttackAbility.cs
parent61fbc2cdd8368505c3c8ce893af020463cc2a669 (diff)
*misc
Diffstat (limited to 'Assets/Scripts/Avatar/Abilities/AttackAbility.cs')
-rw-r--r--Assets/Scripts/Avatar/Abilities/AttackAbility.cs143
1 files changed, 143 insertions, 0 deletions
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();
+
+ /// <summary>
+ /// 在跑动状态时可以切换的ability
+ /// </summary>
+ private List<Trigger> m_Triggers = new List<Trigger>();
+
+ private List<Trigger> m_LateTriggers = new List<Trigger>();
+
+ /// <summary>
+ /// 这个招式所有hit的效果
+ /// </summary>
+ public HitDefination[] HitDef;
+
+ /// <summary>
+ /// 从动画结束开始计时
+ /// </summary>
+ float m_TimeCount;
+ public float ExpireTime
+ {
+ get
+ {
+ return m_TimeCount;
+ }
+ }
+
+ /// <summary>
+ /// 这个招式的hit个数
+ /// </summary>
+ 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);
+ }
+
+}