diff options
author | chai <chaifix@163.com> | 2021-09-01 08:30:42 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-09-01 08:30:42 +0800 |
commit | a5c191cf74238084d9bd9f805b4b6755f70d956d (patch) | |
tree | 06c0f5a85e6bda587205e5b2bea8e2d9fab4f373 /Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs | |
parent | 340bb7224b4f100413541df3b937d90be028a8b1 (diff) |
*改变目录结构
Diffstat (limited to 'Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs')
-rw-r--r-- | Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs new file mode 100644 index 00000000..8a265f45 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs @@ -0,0 +1,217 @@ +#define ANIM_CROSS_FADE +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PCAnimation : UnitAnimation +{ + 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, + } + +#if !ANIM_CROSS_FADE + // 切换动画 + public enum ETrigger + { + ToIdle, + ToMove, + ToJump, + ToAttack, + ToAirAttack, + ToLanding, + } +#endif + + private UnitActionData m_ActionData; + + public bool applyRootMotion { get; set; }// 动态设置root motion + public bool applyRootCurve { get; set; } // 程序生成的root motion + + public override void Initialize() + { + base.Initialize(); + + m_Animator = this.m_Owner.unitObj.GetComponent<Animator>(); + + m_Animator.speed = 0; + + m_LayerInfo = new AnimatorLayerInfo[2]; + m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, (int)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 AnimJump() + { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("Jump", 0.01f); +#else + ResetAllTriggers(); + SetTrigger(ETrigger.ToJump); +#endif + } + + public void AnimAirAttack(int id) + { + m_Owner.unitCollider.OnAnimationChange(); +#if ANIM_CROSS_FADE + m_Animator.CrossFade("AirAttack" + id, 0.05f); +#else + ResetAllTriggers(); + SetTrigger(ETrigger.ToAirAttack); +#endif + } + + public void AnimAttack(int id) + { + m_Owner.unitCollider.OnAnimationChange(); + m_Animator.CrossFade("Attack" + id, 0.05f); + } + + 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 + } + +#if !ANIM_CROSS_FADE + void ResetAllTriggers() + { + var values = Enum.GetValues(typeof(ETrigger)); + foreach (var e in values) + { + m_Animator.ResetTrigger(e.ToString()); + } + } +#endif + + private void Play(string animState, float fade = 0.1f, float offset = 0f, int layer = 0) + { + m_Animator.CrossFade(animState, fade, layer, offset); + } +} |