summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Component
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit/Component')
-rw-r--r--Assets/Scripts/Unit/Component/UnitAnimation.cs35
-rw-r--r--Assets/Scripts/Unit/Component/UnitState.cs135
2 files changed, 151 insertions, 19 deletions
diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs b/Assets/Scripts/Unit/Component/UnitAnimation.cs
index a6a7f3eb..4532023d 100644
--- a/Assets/Scripts/Unit/Component/UnitAnimation.cs
+++ b/Assets/Scripts/Unit/Component/UnitAnimation.cs
@@ -286,6 +286,9 @@ public class UnitAnimation : UnitComponent
public AnimatorLayerInfo[] layers { get { return m_LayerInfo; } }
private readonly AnimatorLayerInfo[] m_LayerInfo = new AnimatorLayerInfo[(int)ELayer.Count];
+ public bool applyRootMotion { get; set; }// 动态设置root motion
+ public bool applyRootCurve { get; set; } // 程序生成的root motion
+
public bool isInTransition
{
get
@@ -309,6 +312,8 @@ public class UnitAnimation : UnitComponent
{
LogHelper.LogError("没有挂Animator组件");
}
+
+ applyRootMotion = true;
}
public override void OnUpdate()
@@ -317,8 +322,12 @@ public class UnitAnimation : UnitComponent
UpdateLayer();
UpdateAnimation();
- UpdateRootMotion();
- }
+
+ if(applyRootMotion)
+ UpdateRootMotion();
+ if(applyRootCurve)
+ UpdateRootCurve();
+ }
void UpdateLayer()
{
@@ -342,7 +351,13 @@ public class UnitAnimation : UnitComponent
m_Owner.unitRootMotion.UpdateRootMotion();
}
- public void AnimIdle()
+ void UpdateRootCurve()
+ {
+
+ }
+
+
+ public void AnimIdle()
{
#if ANIM_CROSS_FADE
m_Animator.CrossFade("Idle", 0.2f, 0);
@@ -394,7 +409,19 @@ public class UnitAnimation : UnitComponent
#endif
}
- public void AnimLanding()
+ 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);
diff --git a/Assets/Scripts/Unit/Component/UnitState.cs b/Assets/Scripts/Unit/Component/UnitState.cs
index 7a731b02..bc934f43 100644
--- a/Assets/Scripts/Unit/Component/UnitState.cs
+++ b/Assets/Scripts/Unit/Component/UnitState.cs
@@ -20,6 +20,7 @@ public class UnitState : UnitComponent
//
Attack ,
AirAttack ,
+ AirDash ,
//
HitAir ,
HitAirHit ,
@@ -63,6 +64,11 @@ public class UnitState : UnitComponent
}
+ public struct AirDashParam
+ {
+
+ }
+
public struct JumpParam
{ }
@@ -114,6 +120,21 @@ public class UnitState : UnitComponent
IEnumerator Nein() { yield break; }
void OnNienExit(EUnitState nextState) { }
+ public void TurnAround(bool bRight)
+ {
+ m_Owner.transform.rotation = Quaternion.Euler(0, bRight ? 0 : 180, 0);
+ }
+
+ public void TurnLeft()
+ {
+ TurnAround(false);
+ }
+
+ public void TurnRight()
+ {
+ TurnAround(true);
+ }
+
#region Idle
IEnumerator Idle(IdleParam param)
@@ -212,14 +233,36 @@ public class UnitState : UnitComponent
yield return null; // 等待animator更新
while (true)
{
- bool canAttack = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
- if(canAttack && Input.GetKeyDown("j") )
- {
- ++id;
- m_Owner.unitAnimation.AnimAirAttack(id);
- yield return null; // 等待animator更新
- yield return new WaitForTransitionDone(m_Owner.unitAnimation);
- }
+ bool canCombo = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
+ if(canCombo)
+ {
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A))
+ {
+ TurnLeft();
+ ChangeState(EUnitState.AirDash, new AirDashParam());
+ }
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D))
+ {
+ TurnRight();
+ ChangeState(EUnitState.AirDash, new AirDashParam());
+ }
+
+ if (Input.GetKeyDown("j"))
+ {
+ if (Input.GetKey("a"))
+ {
+ TurnAround(false);
+ }
+ if (Input.GetKey("d"))
+ {
+ TurnAround(true);
+ }
+ ++id;
+ m_Owner.unitAnimation.AnimAirAttack(id);
+ yield return null; // 等待animator更新
+ yield return new WaitForTransitionDone(m_Owner.unitAnimation);
+ }
+ }
bool reachEnd = m_Owner.unitAnimation.layers[0].playbackNomralizedTime == 1;
if (reachEnd)
@@ -236,11 +279,63 @@ public class UnitState : UnitComponent
}
- #endregion
+ #endregion
+
+ #region AirDash
+
+ IEnumerator AirDash(AirDashParam param)
+ {
+ m_Owner.unitAnimation.AnimAirDash();
+ yield return null;
+ while(true)
+ {
+ bool reachEnd = m_Owner.unitAnimation.layers[0].playbackNomralizedTime == 1;
+ if (reachEnd)
+ {
+ ChangeState(EUnitState.Landing, new LandingParam());
+ }
+
+ bool canCombo = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
+ if(canCombo)
+ {
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A))
+ {
+ TurnLeft();
+ m_Owner.unitAnimation.AnimAirDash();
+ }
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D))
+ {
+ TurnRight();
+ m_Owner.unitAnimation.AnimAirDash();
+ }
+
+ if (Input.GetKeyDown("j"))
+ {
+ if (Input.GetKey("a"))
+ {
+ TurnAround(false);
+ }
+ if (Input.GetKey("d"))
+ {
+ TurnAround(true);
+ }
+ ChangeState(EUnitState.AirAttack, new SkillParam());
+ }
+ }
+
+ yield return null;
+ }
+ }
+
+ void OnAirDashExit(EUnitState next)
+ {
+ }
+
+ #endregion
- #region Jump
+ #region Jump
- IEnumerator Jump(JumpParam param)
+ IEnumerator Jump(JumpParam param)
{
unitAnimation.AnimJump();
yield return null;
@@ -271,18 +366,28 @@ public class UnitState : UnitComponent
m_Owner.unitAnimation.AnimLanding();
yield return null;
yield return new WaitForTransitionDone(m_Owner.unitAnimation);
- float vy = 0;
+ float vy = 2;
float g = 9.8f;
bool landingGround = false;
+ float vz = 5;
while (true)
{
Vector3 pos = m_Owner.transform.position;
vy += g * Time.deltaTime;
pos.y -= vy * Time.deltaTime;
pos.y = Mathf.Max(0, pos.y);
- m_Owner.transform.position = pos;
- Debug.Log(pos.y);
- if(pos.y > 0 && pos.y <= 1 && !landingGround)
+ if (Input.GetKey("a"))
+ {
+ TurnAround(false);
+ pos.x -= vz * Time.deltaTime;
+ }
+ if (Input.GetKey("d"))
+ {
+ TurnAround(true);
+ pos.x += vz * Time.deltaTime;
+ }
+ m_Owner.transform.position = pos;
+ if (pos.y > 0 && pos.y <= 1 && !landingGround)
{
landingGround = true;
m_Owner.unitAnimation.AnimLandingGround();