summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Component/UnitState.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-08-29 12:54:37 +0800
committerchai <chaifix@163.com>2021-08-29 12:54:37 +0800
commitde78537f8edc6cb162ba58520956255f7e53769d (patch)
tree1bf05e3910149bffb79fb0c96e9ef1e28ea126e1 /Assets/Scripts/Unit/Component/UnitState.cs
parente2284510c40e2d637c28108b50df2e403d51ec1c (diff)
*轴向改为xy
Diffstat (limited to 'Assets/Scripts/Unit/Component/UnitState.cs')
-rw-r--r--Assets/Scripts/Unit/Component/UnitState.cs135
1 files changed, 120 insertions, 15 deletions
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();