summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Unit/Component/UnitAnimation.cs50
-rw-r--r--Assets/Scripts/Unit/Component/UnitState.cs18
-rw-r--r--Assets/Scripts/Unit/UnitRootMotion.cs9
3 files changed, 63 insertions, 14 deletions
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);
+ }
+
}
diff --git a/Assets/Scripts/Unit/Component/UnitState.cs b/Assets/Scripts/Unit/Component/UnitState.cs
index e27aa00b..7a731b02 100644
--- a/Assets/Scripts/Unit/Component/UnitState.cs
+++ b/Assets/Scripts/Unit/Component/UnitState.cs
@@ -120,7 +120,7 @@ public class UnitState : UnitComponent
{
if(m_Owner.isInAir) // 浮空切换到landing
{
-
+ ChangeState(EUnitState.Landing, new LandingParam());
}
else // idle
{
@@ -151,7 +151,6 @@ public class UnitState : UnitComponent
void OnIdleExit(EUnitState nextState)
{
- m_Owner.unitAnimation.animator.ResetTrigger("ToIdle");
}
#endregion
@@ -208,13 +207,16 @@ public class UnitState : UnitComponent
IEnumerator AirAttack(SkillParam param)
{
- m_Owner.unitAnimation.AnimAirAttack();
+ int id = 0;
+ m_Owner.unitAnimation.AnimAirAttack(id);
+ yield return null; // 等待animator更新
while (true)
{
bool canAttack = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
if(canAttack && Input.GetKeyDown("j") )
{
- m_Owner.unitAnimation.AnimAirAttack();
+ ++id;
+ m_Owner.unitAnimation.AnimAirAttack(id);
yield return null; // 等待animator更新
yield return new WaitForTransitionDone(m_Owner.unitAnimation);
}
@@ -267,8 +269,10 @@ public class UnitState : UnitComponent
IEnumerator Landing(LandingParam param)
{
m_Owner.unitAnimation.AnimLanding();
+ yield return null;
+ yield return new WaitForTransitionDone(m_Owner.unitAnimation);
float vy = 0;
- float g = 9.8f * 1.5f;
+ float g = 9.8f;
bool landingGround = false;
while (true)
{
@@ -281,10 +285,12 @@ public class UnitState : UnitComponent
if(pos.y > 0 && pos.y <= 1 && !landingGround)
{
landingGround = true;
- m_Owner.unitAnimation.AnimLanding();
+ m_Owner.unitAnimation.AnimLandingGround();
}
if(pos.y <= 0)
{
+ pos.y = 0;
+ m_Owner.transform.position = pos;
ChangeState(EUnitState.Idle, new IdleParam());
}
yield return null;
diff --git a/Assets/Scripts/Unit/UnitRootMotion.cs b/Assets/Scripts/Unit/UnitRootMotion.cs
index 58ae814e..c4d4b2c9 100644
--- a/Assets/Scripts/Unit/UnitRootMotion.cs
+++ b/Assets/Scripts/Unit/UnitRootMotion.cs
@@ -72,7 +72,14 @@ public class UnitRootMotion : UnitComponent
{
Vector3 dest = m_Owner.unitAnimation.animator.deltaPosition;
dest.x = 0; //限制x轴始终在x=0
- m_Owner.transform.position += dest;
+
+ var state = m_Owner.unitAnimation.layers[0].stateInfo;
+ if(state.IsTag("IgnoreY"))
+ {
+ dest.y = 0;
+ }
+
+ m_Owner.transform.position += dest;
}
#endif