diff options
Diffstat (limited to 'Assets/Scripts/Unit/Component/UnitAnimation.cs')
-rw-r--r-- | Assets/Scripts/Unit/Component/UnitAnimation.cs | 93 |
1 files changed, 71 insertions, 22 deletions
diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs b/Assets/Scripts/Unit/Component/UnitAnimation.cs index 7491d44c..5649206e 100644 --- a/Assets/Scripts/Unit/Component/UnitAnimation.cs +++ b/Assets/Scripts/Unit/Component/UnitAnimation.cs @@ -1,4 +1,5 @@ -using System.Collections;
+using System;
+using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
@@ -53,7 +54,13 @@ public class AnimatorLayerInfo {
get
{
- return m_Animator.GetCurrentAnimatorStateInfo(layerIndex);
+ AnimatorStateInfo stateInfo = m_Animator.GetCurrentAnimatorStateInfo(layerIndex);
+ AnimatorClipInfo[] clips = m_Animator.GetCurrentAnimatorClipInfo(layerIndex);
+ if(clips == null || clips.Length == 0)
+ {
+ stateInfo = m_Animator.GetNextAnimatorStateInfo(layerIndex);
+ }
+ return stateInfo;
}
}
@@ -64,7 +71,13 @@ public class AnimatorLayerInfo {
get
{
- return m_Animator.GetCurrentAnimatorClipInfo(layerIndex);
+ AnimatorClipInfo[] clips = m_Animator.GetCurrentAnimatorClipInfo(layerIndex);
+ if(clips.Length == 0)
+ {
+ // 如果transition设置了打断,会出现GetCurrentAnimatorClipinfo返回空数组的情况
+ clips = m_Animator.GetNextAnimatorClipInfo(layerIndex);
+ }
+ return clips;
}
}
@@ -103,12 +116,15 @@ public class AnimatorLayerInfo }
}
- // 播放进度百分比
+ // 播放进度百分比,[0-1],是逻辑上的,如果动画不是loop,那么播放完后normalizedTime是1
public float playbackNomralizedTime
{
get
{
- return stateInfo.normalizedTime;
+ //return stateInfo.normalizedTime % 1f;
+ if (!stateInfo.loop && stateInfo.normalizedTime > 1)
+ return 1;
+ return stateInfo.normalizedTime % 1f;
}
}
@@ -185,13 +201,20 @@ public class AnimatorLayerInfo }
}
+ public bool IsToggleOpen(EAnimationToogle toggle)
+ {
+ if (m_AnimationData == null)
+ return false;
+ return m_AnimationData.IsToggleOpen(toggle, playbackNomralizedTime);
+ }
+
public void OnUpdate()
{
- // 执行事件
- m_TimelineEventProxy.ExecuteAnimationEvents(animationData, playbackTimeInSeconds * TimelineEventProxy.FPS);
+ // 执行事件
+ m_TimelineEventProxy.ExecuteAnimationEvents(animationData, playbackTimeInSeconds * TimelineEventProxy.FPS);
- // 播放速度控制
- if(applySpeedCurve && animationData.speedCurve != null)
+ // 播放速度控制
+ if (applySpeedCurve && animationData != null && animationData.speedCurve != null)
{
playbackSpeed = animationData.speedCurve.Evaluate(playbackNomralizedTime);
}
@@ -231,6 +254,16 @@ public class UnitAnimation : UnitComponent Stinger,
Turn,
Landing,
+
+ AirAttack0,
+ AirAttack1,
+ AirAttack2,
+ AirAttack3,
+
+ Attack0,
+ Attack1,
+ Attack2,
+ Attack3,
}
// 切换动画
@@ -238,9 +271,10 @@ public class UnitAnimation : UnitComponent {
ToIdle,
ToMove,
- ToAttack,
ToJump,
- ToAirAttack,
+ ToAttack,
+ ToAirAttack,
+ ToLanding,
}
public Animator animator { get { return m_Animator; } }
@@ -268,7 +302,7 @@ public class UnitAnimation : UnitComponent m_Animator.speed = 0;
m_LayerInfo[0] = new AnimatorLayerInfo(this, m_Animator, ELayer.Basic);
- m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack);
+ //m_LayerInfo[1] = new AnimatorLayerInfo(this, m_Animator, ELayer.Attack);
if (m_Animator == null)
{
@@ -309,38 +343,53 @@ public class UnitAnimation : UnitComponent public void AnimIdle()
{
- if(layers[0].stateInfo.shortNameHash != Animator.StringToHash("Idle"))
- {
- m_Animator.SetTrigger(ETrigger.ToIdle.ToString());
- }
+ ResetAllTriggers();
+ m_Animator.SetTrigger(ETrigger.ToIdle.ToString());
}
public void AnimMove()
{
- if (layers[0].stateInfo.shortNameHash != Animator.StringToHash("Move"))
- {
- m_Animator.SetTrigger(ETrigger.ToMove.ToString());
- }
+ ResetAllTriggers();
+ m_Animator.SetTrigger(ETrigger.ToMove.ToString());
}
public void AnimAttack()
{
+ ResetAllTriggers();
SetTrigger(ETrigger.ToAttack);
}
void SetTrigger(ETrigger trigger)
{
+ ResetAllTriggers();
m_Animator.SetTrigger(trigger.ToString());
}
public void AnimJump()
{
- SetTrigger(ETrigger.ToJump);
+ ResetAllTriggers();
+ SetTrigger(ETrigger.ToJump);
}
public void AnimAirAttack()
{
- SetTrigger(ETrigger.ToAirAttack);
+ ResetAllTriggers();
+ SetTrigger(ETrigger.ToAirAttack);
}
+ public void AnimLanding()
+ {
+ ResetAllTriggers();
+ SetTrigger(ETrigger.ToLanding);
+ }
+
+ void ResetAllTriggers()
+ {
+ var values = Enum.GetValues(typeof(ETrigger));
+ foreach(var e in values)
+ {
+ m_Animator.ResetTrigger(e.ToString());
+ }
+ }
+
}
|