From e2284510c40e2d637c28108b50df2e403d51ec1c Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 27 Aug 2021 18:53:44 +0800 Subject: *crossfade --- Assets/Scripts/Unit/Component/UnitAnimation.cs | 50 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 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 5649206e..a6a7f3eb 100644 --- a/Assets/Scripts/Unit/Component/UnitAnimation.cs +++ b/Assets/Scripts/Unit/Component/UnitAnimation.cs @@ -1,4 +1,5 @@ -using System; +#define ANIM_CROSS_FADE +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -102,7 +103,7 @@ public class AnimatorLayerInfo { get { - return stateInfo.normalizedTime * clipInfo[0].clip.length; + return playbackNomralizedTime * clipInfo[0].clip.length; } } @@ -343,15 +344,23 @@ public class UnitAnimation : UnitComponent public void AnimIdle() { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("Idle", 0.2f, 0); +#else ResetAllTriggers(); - m_Animator.SetTrigger(ETrigger.ToIdle.ToString()); - } + 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() { @@ -367,20 +376,42 @@ public class UnitAnimation : UnitComponent public void AnimJump() { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("Jump", 0.01f); +#else ResetAllTriggers(); SetTrigger(ETrigger.ToJump); - } +#endif + } - public void AnimAirAttack() + public void AnimAirAttack(int id) { +#if ANIM_CROSS_FADE + m_Animator.CrossFade("AirAttack" + id, 0.05f); +#else ResetAllTriggers(); SetTrigger(ETrigger.ToAirAttack); +#endif } 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() @@ -392,4 +423,9 @@ public class UnitAnimation : UnitComponent } } + 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