From cf4e1f9833c810e18429ddf40f4bcf9052ff17ac Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 29 Aug 2021 19:44:31 +0800 Subject: *monster --- Assets/Scripts/Unit/Component/UnitAnimation.cs | 223 +------------------------ 1 file changed, 7 insertions(+), 216 deletions(-) (limited to 'Assets/Scripts/Unit/Component/UnitAnimation.cs') diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs b/Assets/Scripts/Unit/Component/UnitAnimation.cs index 4532023d..3df9ef89 100644 --- a/Assets/Scripts/Unit/Component/UnitAnimation.cs +++ b/Assets/Scripts/Unit/Component/UnitAnimation.cs @@ -10,7 +10,7 @@ using UnityEditor; // 单独一层动画 public class AnimatorLayerInfo { - public UnitAnimation.ELayer layer; + public int layer; public int layerIndex { get { return (int)layer; } } @@ -178,7 +178,7 @@ public class AnimatorLayerInfo TimelineEventProxy m_TimelineEventProxy; - public AnimatorLayerInfo(UnitAnimation unitAnimation, Animator animator, UnitAnimation.ELayer layer) + public AnimatorLayerInfo(UnitAnimation unitAnimation, Animator animator, int layer) { this.m_UnitAnimation = unitAnimation; this.m_Animator = animator; @@ -231,65 +231,14 @@ public class AnimatorLayerInfo [DisallowMultipleComponent] public class UnitAnimation : UnitComponent { - public enum ELayer - { - Basic = 0, - Attack, - SwordAttack, - GunAttack, - UpperBody, - LowerBody, - Count, - } - - // 动作名,和animator里的state对应 - public enum EAnimState - { - // layer 0 - Idle = 0, - Move, - Jump, - Hit, - Attack, - Rise, - Stinger, - Turn, - Landing, - - AirAttack0, - AirAttack1, - AirAttack2, - AirAttack3, - - Attack0, - Attack1, - Attack2, - Attack3, - } - - // 切换动画 - public enum ETrigger - { - ToIdle, - ToMove, - ToJump, - ToAttack, - ToAirAttack, - ToLanding, - } - - public Animator animator { get { return m_Animator; } } - private Animator m_Animator; - - private UnitActionData m_ActionData; - public AnimatorLayerInfo[] layers { get { return m_LayerInfo; } } - private readonly AnimatorLayerInfo[] m_LayerInfo = new AnimatorLayerInfo[(int)ELayer.Count]; + protected AnimatorLayerInfo[] m_LayerInfo; + + public Animator animator { get { return m_Animator; } } + protected Animator m_Animator; - public bool applyRootMotion { get; set; }// 动态设置root motion - public bool applyRootCurve { get; set; } // 程序生成的root motion - public bool isInTransition + public bool isInTransition { get { @@ -297,162 +246,4 @@ public class UnitAnimation : UnitComponent } } - public override void Initialize() - { - base.Initialize(); - - m_Animator = this.m_Owner.unitObj.GetComponent(); - - m_Animator.speed = 0; - - m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, ELayer.Basic); - //m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack); - - if (m_Animator == null) - { - LogHelper.LogError("没有挂Animator组件"); - } - - applyRootMotion = true; - } - - public override void OnUpdate() - { - base.OnUpdate(); - - UpdateLayer(); - UpdateAnimation(); - - if(applyRootMotion) - UpdateRootMotion(); - if(applyRootCurve) - UpdateRootCurve(); - } - - void UpdateLayer() - { - m_LayerInfo[0].OnUpdate(); - return; - for (int i = 0; i < m_LayerInfo.Length; ++i) - { - m_LayerInfo[i].OnUpdate(); - } - } - - void UpdateAnimation() - { - m_Animator.speed = 1; - m_Animator.Update(Time.deltaTime); - m_Animator.speed = 0; - } - - void UpdateRootMotion() - { - m_Owner.unitRootMotion.UpdateRootMotion(); - } - - void UpdateRootCurve() - { - - } - - - public void AnimIdle() - { -#if ANIM_CROSS_FADE - m_Animator.CrossFade("Idle", 0.2f, 0); -#else - ResetAllTriggers(); - m_Animator.SetTrigger(ETrigger.ToIdle.ToString()); -#endif - } - - public void AnimMove() - { -#if ANIM_CROSS_FADE - m_Animator.CrossFade("Move", 0.01f, 0); -#else - ResetAllTriggers(); - m_Animator.SetTrigger(ETrigger.ToMove.ToString()); -#endif - } - - public void AnimAttack() - { - ResetAllTriggers(); - SetTrigger(ETrigger.ToAttack); - } - - void SetTrigger(ETrigger trigger) - { - ResetAllTriggers(); - m_Animator.SetTrigger(trigger.ToString()); - } - - public void AnimJump() - { -#if ANIM_CROSS_FADE - m_Animator.CrossFade("Jump", 0.01f); -#else - ResetAllTriggers(); - SetTrigger(ETrigger.ToJump); -#endif - } - - public void AnimAirAttack(int id) - { -#if ANIM_CROSS_FADE - m_Animator.CrossFade("AirAttack" + id, 0.05f); -#else - ResetAllTriggers(); - SetTrigger(ETrigger.ToAirAttack); -#endif - } - - public void AnimAirDash() - { - if (layers[0].stateInfo.IsName("AirDash")) - { - m_Animator.Play("AirDash", 0, 0); - } - else - { - m_Animator.CrossFade("AirDash", 0.05f); - } - } - - public void AnimLanding() - { -#if ANIM_CROSS_FADE - m_Animator.CrossFade("Landing", 0.05f); -#else - ResetAllTriggers(); - SetTrigger(ETrigger.ToLanding); -#endif - } - - public void AnimLandingGround() - { -#if ANIM_CROSS_FADE - m_Animator.CrossFade("LandingGround", 0.00f); -#else - ResetAllTriggers(); - SetTrigger(ETrigger.ToLanding); -#endif - } - - void ResetAllTriggers() - { - var values = Enum.GetValues(typeof(ETrigger)); - foreach(var e in values) - { - m_Animator.ResetTrigger(e.ToString()); - } - } - - private void Play(string animState, float fade = 0.1f, float offset = 0f, int layer = 0) - { - m_Animator.CrossFade(animState, fade, layer, offset); - } - } -- cgit v1.1-26-g67d0