From de78537f8edc6cb162ba58520956255f7e53769d Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 29 Aug 2021 12:54:37 +0800 Subject: =?UTF-8?q?*=E8=BD=B4=E5=90=91=E6=94=B9=E4=B8=BAxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Unit/Component/UnitState.cs | 135 +++++++++++++++++++++++++---- 1 file changed, 120 insertions(+), 15 deletions(-) (limited to 'Assets/Scripts/Unit/Component/UnitState.cs') 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(); -- cgit v1.1-26-g67d0