From 9f447daa59fe9393904206499e6872068a11e7f8 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 26 Aug 2021 19:03:33 +0800 Subject: *misc --- Assets/Scripts/Unit/Component/UnitState.cs | 101 ++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 23 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 0ad1ec58..e27aa00b 100644 --- a/Assets/Scripts/Unit/Component/UnitState.cs +++ b/Assets/Scripts/Unit/Component/UnitState.cs @@ -17,7 +17,9 @@ public class UnitState : UnitComponent Spawn , Die , Dead , - Skill , + // + Attack , + AirAttack , // HitAir , HitAirHit , @@ -126,10 +128,10 @@ public class UnitState : UnitComponent m_Owner.unitAnimation.AnimIdle(); while (true) { - if (Input.GetKeyDown("j")) - { - ChangeState(EUnitState.Skill, new SkillParam()); - } + //if (Input.GetKeyDown("j")) + //{ + // ChangeState(EUnitState.Attack, new SkillParam()); + //} if (Input.GetKeyDown("space")) { ChangeState(EUnitState.Jump, new JumpParam()); @@ -183,26 +185,60 @@ public class UnitState : UnitComponent #endregion - #region Skill + #region Attack - IEnumerator Skill(SkillParam param) + IEnumerator Attack(SkillParam param) { - m_Owner.unitAnimation.AnimAttack(); - yield return new WaitForTransitionDone(m_Owner.unitAnimation); - yield return new WaitForActionReachEnd(m_Owner.unitAnimation); - ChangeState(EUnitState.Idle, new IdleParam()); - } + while(true) + { + - void OnSkillExit(EUnitState next) + yield return null; + } + } + + void OnAttackExit(EUnitState next) { } - #endregion + #endregion + + #region AirAttack - #region Jump + IEnumerator AirAttack(SkillParam param) + { + m_Owner.unitAnimation.AnimAirAttack(); + while (true) + { + bool canAttack = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); + if(canAttack && Input.GetKeyDown("j") ) + { + m_Owner.unitAnimation.AnimAirAttack(); + yield return null; // 等待animator更新 + yield return new WaitForTransitionDone(m_Owner.unitAnimation); + } + + bool reachEnd = m_Owner.unitAnimation.layers[0].playbackNomralizedTime == 1; + if (reachEnd) + { + ChangeState(EUnitState.Landing, new LandingParam()); + } + + yield return null; + } + } + + void OnAirAttackExit(EUnitState next) + { - IEnumerator Jump(JumpParam param) + } + + #endregion + + #region Jump + + IEnumerator Jump(JumpParam param) { unitAnimation.AnimJump(); yield return null; @@ -211,9 +247,10 @@ public class UnitState : UnitComponent { if (unitAnimation.layers[0].playbackNomralizedTime >= 1) ChangeState(EUnitState.Idle, new IdleParam()); - if (Input.GetKeyDown("j")) + bool canAttack = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo); + if (Input.GetKeyDown("j") && canAttack) { - ChangeState(EUnitState.Skill, new SkillParam()); + ChangeState(EUnitState.AirAttack, new SkillParam()); } yield return null; } @@ -229,11 +266,29 @@ public class UnitState : UnitComponent IEnumerator Landing(LandingParam param) { - yield return new WaitForLanding(m_Owner); - Vector3 pos = m_Owner.transform.position; - pos.y = 0; - m_Owner.transform.position = pos; - ChangeState(EUnitState.Idle); + m_Owner.unitAnimation.AnimLanding(); + float vy = 0; + float g = 9.8f * 1.5f; + bool landingGround = false; + 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) + { + landingGround = true; + m_Owner.unitAnimation.AnimLanding(); + } + if(pos.y <= 0) + { + ChangeState(EUnitState.Idle, new IdleParam()); + } + yield return null; + } } void OnLandingExit(EUnitState next) -- cgit v1.1-26-g67d0