diff options
Diffstat (limited to 'Assets/Scripts/Unit/Components/UnitState/PCState_States.cs')
-rw-r--r-- | Assets/Scripts/Unit/Components/UnitState/PCState_States.cs | 383 |
1 files changed, 383 insertions, 0 deletions
diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState_States.cs b/Assets/Scripts/Unit/Components/UnitState/PCState_States.cs new file mode 100644 index 00000000..2cfaf876 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitState/PCState_States.cs @@ -0,0 +1,383 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public partial class PCState : UnitState
+{
+
+ #region state param + public struct IdleParam { } + + public struct MoveParam + { + public bool isRight; + public string key; + } + + public struct SkillParam + { + public float offset;
+ } + + public struct AirDashParam + { + + } + + public struct JumpParam + { } + + public struct TurnParam + { + EUnitState nextState; + } + + public struct LandingParam { }
+
+ #endregion +
+ IEnumerator Nein() { yield break; } + void OnNienExit(EUnitState nextState) { } +
+ #region Idle +
+ IEnumerator Idle(IdleParam param) + {
+ //if (m_Owner.isInAir) // 浮空切换到landing
+ //{
+ // ChangeState(EUnitState.Landing, new LandingParam());
+ //}
+ //else // idle
+ //{
+ m_Owner.SetYPosition(0);
+ m_Owner.pcAnimation.AnimIdle();
+ while (true)
+ {
+ if (Input.GetKeyDown("j"))
+ {
+ ChangeState(EUnitState.Attack, new SkillParam());
+ }
+ if (Input.GetKeyDown("u"))
+ {
+ ChangeState(EUnitState.AttackToAir, new SkillParam());
+ }
+ if (Input.GetKeyDown("space"))
+ {
+ ChangeState(EUnitState.Jump, new JumpParam());
+ }
+ if (Input.GetKey("d"))
+ {
+ MoveParam move = new MoveParam();
+ move.isRight = true;
+ move.key = "d";
+ ChangeState(EUnitState.Move, move);
+ }
+ if (Input.GetKey("a"))
+ {
+ MoveParam move = new MoveParam();
+ move.isRight = false;
+ move.key = "a";
+ ChangeState(EUnitState.Move, move);
+ }
+ yield return null;
+ } + //} + } + + void OnIdleExit(EUnitState nextState) + { + } + #endregion + + #region Move + IEnumerator Move(MoveParam param) + { + if (m_Owner.isTowardRight && !param.isRight + || !m_Owner.isTowardRight && param.isRight) + { + //m_Owner.pcAnimation.Play(UnitAnimation.EAnimState.Turn); + //yield return new WaitForActionReachEnd(m_Owner.pcAnimation); + //if (param.isRight) + // m_Owner.transform.rotation = Quaternion.Euler(0, 0, 0); + //else + // m_Owner.transform.rotation = Quaternion.Euler(0, 180, 0); + m_Owner.transform.rotation = Quaternion.Euler(0, param.isRight ? 0 : 180, 0); + } + //if (Input.GetKey(param.key)) + m_Owner.pcAnimation.AnimMove(); + while (Input.GetKey(param.key)) + { + yield return null; + } + ChangeState(EUnitState.Idle, new IdleParam()); + } + + void OnMoveExit(EUnitState nextState) + { + m_Owner.pcAnimation.animator.ResetTrigger("ToMove"); + }
+
+ #endregion +
+ #region Attack +
+ IEnumerator Attack(SkillParam param)
+ {
+ const int total = 4;
+ int id = 0;
+ m_Owner.pcAnimation.AnimAttack(id++);
+ yield return null;
+ while (true)
+ {
+ if (isComboOpen)
+ {
+ //if (InputManager.Instance.TryCommand(0.5f, KeyCode.W, KeyCode.J))
+ if (Input.GetKeyDown("u")) + {
+ SkillParam skill = new SkillParam();
+ skill.offset = 0.12f;
+ ChangeState(EUnitState.AttackToAir, skill);
+ }
+ }
+
+ if (isComboOpen && id < total)
+ {
+ if (Input.GetKeyDown("j"))
+ {
+ TryTurnAround(); +
+ m_Owner.pcAnimation.AnimAttack(id++);
+ yield return null;
+ yield return new WaitForTransitionDone(m_Owner.pcAnimation);
+ }
+ }
+
+ if (isAnimationReachEnd)
+ {
+ ChangeState(EUnitState.Idle, new IdleParam());
+ }
+
+ yield return null;
+ }
+ } + + void OnAttackExit(EUnitState next) + { + }
+
+ #endregion +
+ #region AttackToAir +
+ IEnumerator AttackToAir(SkillParam param)
+ {
+ m_Owner.pcAnimation.AnimAttackToAir(param.offset);
+ yield return null; + InputManager.Instance.ClearCommand(); + while (true)
+ {
+ TryTianyin();
+
+ if (isComboOpen)
+ {
+ TryDash();
+
+ if (InputManager.Instance.TryCommand(0.5f, false, KeyCode.J))
+ {
+ ChangeState(EUnitState.AirAttack, new SkillParam());
+ }
+ }
+
+ if (isAnimationReachEnd) + { + ChangeState(EUnitState.Landing, new LandingParam()); + }
+ yield return null;
+ }
+ }
+
+ void OnAttackToAirExit(EUnitState next)
+ {
+ }
+
+ #endregion +
+ #region AirAttack +
+ IEnumerator AirAttack(SkillParam param) + { + int total = 5;
+ int id = 0;
+ m_Owner.pcAnimation.AnimAirAttack(id++); + yield return null; + InputManager.Instance.ClearCommand(); + while (true) + {
+ TryTeleport();
+
+ TryTianyin(); + + if (isComboOpen) + {
+ TryDash(); + + if (InputManager.Instance.TryCommand(0.3f, false, KeyCode.J)) + { + TryTurnAround();
+
+ m_Owner.pcAnimation.AnimAirAttack(id++);
+ id %= total; + yield return null; // 等待animator更新 + yield return new WaitForTransitionDone(m_Owner.pcAnimation); + } + } + + if (isAnimationReachEnd) + { + ChangeState(EUnitState.Landing, new LandingParam()); + } + + yield return null; + } + } + + void OnAirAttackExit(EUnitState next) + { + + } + + #endregion + + #region AirDash + + IEnumerator AirDash(AirDashParam param) + { + m_Owner.pcAnimation.AnimAirDash(); + yield return null; + while (true) + { + if (isAnimationReachEnd) + { + ChangeState(EUnitState.Landing, new LandingParam()); + } + + TryTianyin(); + + if (isComboOpen) + { + TryDash(); + + if (Input.GetKeyDown("j")) + {
+ TryTurnAround(); + ChangeState(EUnitState.AirAttack, new SkillParam()); + } + } + + yield return null; + } + } + + void OnAirDashExit(EUnitState next) + { + } + + #endregion + + #region Jump + + IEnumerator Jump(JumpParam param) + { + pcAnimation.AnimJump(); + yield return null; + yield return new WaitForTransitionDone(pcAnimation); + while (true) + { + 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 (isAnimationReachEnd) + ChangeState(EUnitState.Landing, new LandingParam()); + bool canAttack = m_Owner.pcAnimation.baseLayer.IsToggleOpen(EAnimationToogle.Combo); + if (Input.GetKeyDown("j") && canAttack) + { + ChangeState(EUnitState.AirAttack, new SkillParam()); + } + yield return null; + } + } + + void OnJumpExit(EUnitState next) + { + } + + #endregion + + #region Landing + + IEnumerator Landing(LandingParam param) + { + m_Owner.pcAnimation.AnimLanding(); + yield return null; + yield return new WaitForTransitionDone(m_Owner.pcAnimation); + float vy = 0; + float g = -9.8f; + bool landingGround = false; + float vx = 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);
+
+ TryDash(); + + TryTianyin(); + + if (Input.GetKey("a")) + { + TurnAround(false); + pos.x -= vx * Time.deltaTime; + } + if (Input.GetKey("d")) + { + TurnAround(true); + pos.x += vx * Time.deltaTime; + } + if (Input.GetKeyDown("j"))
+ {
+ ChangeState(EUnitState.AirAttack, new SkillParam());
+ } + m_Owner.transform.position = pos; + if (pos.y > 0 && pos.y <= 1 && !landingGround) + { + landingGround = true; + m_Owner.pcAnimation.AnimLandingGround(); + } + if (pos.y <= 0) + { + pos.y = 0; + m_Owner.transform.position = pos; + ChangeState(EUnitState.Idle, new IdleParam()); + } + + yield return null; + } + } + + void OnLandingExit(EUnitState next) + { + }
+
+ #endregion +
+
+}
|