summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Component/UnitState.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Unit/Component/UnitState.cs')
-rw-r--r--Assets/Scripts/Unit/Component/UnitState.cs101
1 files changed, 78 insertions, 23 deletions
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<IdleParam>(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)