summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/Components/UnitState
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-10 20:18:36 +0800
committerchai <chaifix@163.com>2021-09-10 20:18:36 +0800
commit4e46f701027da081d60aa96e0814996c7acfa70a (patch)
treecd4ec98af78dd957e5abb93497db415a708fd93e /Assets/Scripts/Unit/Components/UnitState
parent259d0669aecc184af3c99f3cf9d279f07ae0168f (diff)
*misc
Diffstat (limited to 'Assets/Scripts/Unit/Components/UnitState')
-rw-r--r--Assets/Scripts/Unit/Components/UnitState/PCState.cs456
-rw-r--r--Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs13
-rw-r--r--Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Components/UnitState/PCState_States.cs383
-rw-r--r--Assets/Scripts/Unit/Components/UnitState/PCState_States.cs.meta11
-rw-r--r--Assets/Scripts/Unit/Components/UnitState/UnitState.cs15
6 files changed, 476 insertions, 413 deletions
diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState.cs b/Assets/Scripts/Unit/Components/UnitState/PCState.cs
index c332dcda..0880d369 100644
--- a/Assets/Scripts/Unit/Components/UnitState/PCState.cs
+++ b/Assets/Scripts/Unit/Components/UnitState/PCState.cs
@@ -6,7 +6,7 @@ using UnityEngine;
// 角色状态机
[DisallowMultipleComponent]
-public class PCState : UnitState
+public partial class PCState : UnitState
{
public enum EUnitState
{
@@ -42,6 +42,8 @@ public class PCState : UnitState
[SerializeField] private EUnitState m_State;
public EUnitState CurrentState { get { return m_State; } }
+ private EUnitState m_PrevState;
+
public override void Initialize()
{
base.Initialize();
@@ -56,36 +58,6 @@ public class PCState : UnitState
PCAnimation pcAnimation { get { return m_Owner.pcAnimation; } }
- #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
public void ChangeState<T>(EUnitState nextState, T param = default, bool bForce = false)
{
if (!IsChange(nextState, bForce))
@@ -95,7 +67,6 @@ public class PCState : UnitState
StopAllCoroutines();
- EUnitState prevState = m_State;
string methodFunc = "On" + m_State.ToString() + "Exit";
MethodInfo exitMethod = GetType().GetMethod(methodFunc, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(EUnitState) }, null);
if (exitMethod != null)
@@ -105,9 +76,10 @@ public class PCState : UnitState
else
{
LogHelper.LogError("缺少 " + methodFunc);
- }
+ }
+ m_PrevState = m_State;
m_State = nextState;
-
+
StartCoroutine(m_State.ToString(), param);
}
@@ -118,9 +90,6 @@ public class PCState : UnitState
return false;
}
- IEnumerator Nein() { yield break; }
- void OnNienExit(EUnitState nextState) { }
-
public void TurnAround(bool bRight)
{
m_Owner.transform.rotation = Quaternion.Euler(0, bRight ? 0 : 180, 0);
@@ -134,397 +103,58 @@ public class PCState : UnitState
public void TurnRight()
{
TurnAround(true);
- }
-
- #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)
- {
- bool canCombo = m_Owner.pcAnimation.baseLayer.IsToggleOpen(EAnimationToogle.Combo);
- if (canCombo)
- {
- //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 (canCombo && id < total)
- {
- if (Input.GetKeyDown("j"))
- {
- if (Input.GetKey("a"))
- {
- TurnAround(false);
- }
- if (Input.GetKey("d"))
- {
- TurnAround(true);
- }
- m_Owner.pcAnimation.AnimAttack(id++);
- yield return null;
- yield return new WaitForTransitionDone(m_Owner.pcAnimation);
- }
- }
-
- bool reachEnd = m_Owner.pcAnimation.baseLayer.playbackNormalizedTime == 1;
- if (reachEnd)
- {
- ChangeState(EUnitState.Idle, new IdleParam());
- }
-
- yield return null;
- }
- }
-
- void OnAttackExit(EUnitState next)
- {
}
- #endregion
-
- #region AttackToAir
-
- IEnumerator AttackToAir(SkillParam param)
+ void TryDash()
{
- m_Owner.pcAnimation.AnimAttackToAir(param.offset);
- yield return null;
- InputManager.Instance.ClearCommand();
- while (true)
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A))
{
- bool canCombo = m_Owner.pcAnimation.baseLayer.IsToggleOpen(EAnimationToogle.Combo);
- if(canCombo)
- {
- //if(Input.GetKeyDown("j"))
- if(InputManager.Instance.TryCommand(0.5f, false, KeyCode.J))
- {
- ChangeState(EUnitState.AirAttack, new SkillParam());
- }
- }
-
- bool reachEnd = m_Owner.pcAnimation.baseLayer.playbackNormalizedTime == 1;
- if (reachEnd)
- {
- ChangeState(EUnitState.Landing, new LandingParam());
- }
- yield return null;
+ TurnLeft();
+ ChangeState(EUnitState.AirDash, new AirDashParam(), true);
}
- }
-
- 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; // 等待animator更新
- InputManager.Instance.ClearCommand();
- while (true)
- {
- bool canCombo = m_Owner.pcAnimation.baseLayer.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 (InputManager.Instance.TryCommand(0.3f, false, KeyCode.J))
- {
- if (Input.GetKey("a"))
- {
- TurnAround(false);
- }
- if (Input.GetKey("d"))
- {
- TurnAround(true);
- }
- m_Owner.pcAnimation.AnimAirAttack(id++);
- id %= total;
- yield return null; // 等待animator更新
- yield return new WaitForTransitionDone(m_Owner.pcAnimation);
- }
- }
-
- bool reachEnd = m_Owner.pcAnimation.baseLayer.playbackNormalizedTime == 1;
- if (reachEnd)
- {
- 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)
- {
- bool reachEnd = m_Owner.pcAnimation.baseLayer.playbackNormalizedTime == 1;
- if (reachEnd)
- {
- ChangeState(EUnitState.Landing, new LandingParam());
- }
-
- bool canCombo = m_Owner.pcAnimation.baseLayer.IsToggleOpen(EAnimationToogle.Combo);
- if (canCombo)
- {
- if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A))
- {
- TurnLeft();
- m_Owner.pcAnimation.AnimAirDash();
- }
- if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D))
- {
- TurnRight();
- m_Owner.pcAnimation.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;
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D))
+ {
+ TurnRight();
+ ChangeState(EUnitState.AirDash, new AirDashParam(), true);
}
}
- 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 (pcAnimation.baseLayer.playbackNormalizedTime >= 1)
- ChangeState(EUnitState.Idle, new IdleParam());
- bool canAttack = m_Owner.pcAnimation.baseLayer.IsToggleOpen(EAnimationToogle.Combo);
- if (Input.GetKeyDown("j") && canAttack)
- {
- ChangeState(EUnitState.AirAttack, new SkillParam());
- }
- yield return null;
+ void TryTurnAround()
+ {
+ if (Input.GetKey("a"))
+ {
+ TurnLeft();
+ }
+ if (Input.GetKey("d"))
+ {
+ TurnRight();
}
}
- 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 = 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);
- if (Input.GetKey("a"))
- {
- TurnAround(false);
- pos.x -= vz * Time.deltaTime;
- }
- if (Input.GetKey("d"))
- {
- TurnAround(true);
- pos.x += vz * 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());
- }
-
- 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());
- }
-
- yield return null;
+ void TryTeleport()
+ {
+ if (Input.GetKeyDown("i"))
+ //if (InputManager.Instance.TryCommand(0.5f, KeyCode.I))
+ {
+ float offset = owner.isTowardRight ? 1.5f : -1.5f;
+ owner.center = TestErika.Instance.monster.owner.center + new Vector3(offset, -0.5f, 0);
+ TurnAround(!owner.isTowardRight);
}
}
- void OnLandingExit(EUnitState next)
- {
- }
-
- #endregion
-
- #region timeline event handle
-
- void OnTimeLineEvent(AnimationEventBase animEvent)
- {
+ void TryBlink()
+ {
- }
+ }
- #endregion
+ void TryTianyin()
+ {
+ if (Input.GetKeyDown("o"))
+ {
+ float offset = owner.isTowardRight ? 1.2f : -1.2f;
+ TestErika.Instance.monster.owner.center = owner.center + new Vector3(offset, 0.5f, 0);
+ ((MonsterController)TestErika.Instance.monster.owner).monsterState.ChangeState(MonsterState.EUnitState.HitInAir, new MonsterState.HitInAirParam(), true);
+ }
+ }
} \ No newline at end of file
diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs b/Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs
new file mode 100644
index 00000000..b5c0833f
--- /dev/null
+++ b/Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs
@@ -0,0 +1,13 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public partial class PCState : UnitState
+{
+
+ void OnTimeLineEvent(AnimationEventBase animEvent)
+ {
+
+ }
+
+}
diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs.meta b/Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs.meta
new file mode 100644
index 00000000..7dc2d927
--- /dev/null
+++ b/Assets/Scripts/Unit/Components/UnitState/PCState_Event.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 760f104e062ae884d809b7fc80b041b4
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
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
+
+
+}
diff --git a/Assets/Scripts/Unit/Components/UnitState/PCState_States.cs.meta b/Assets/Scripts/Unit/Components/UnitState/PCState_States.cs.meta
new file mode 100644
index 00000000..e314f21e
--- /dev/null
+++ b/Assets/Scripts/Unit/Components/UnitState/PCState_States.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: bfcb25f32c442a5429ab4d0603b9df67
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Unit/Components/UnitState/UnitState.cs b/Assets/Scripts/Unit/Components/UnitState/UnitState.cs
index aff1e0f3..b94a98df 100644
--- a/Assets/Scripts/Unit/Components/UnitState/UnitState.cs
+++ b/Assets/Scripts/Unit/Components/UnitState/UnitState.cs
@@ -9,5 +9,20 @@ using UnityEngine;
public class UnitState : UnitComponent
{
+ public virtual bool isAnimationReachEnd
+ {
+ get
+ {
+ return owner.unitAnimation.baseLayer.playbackNormalizedTime == 1;
+ }
+ }
+
+ public virtual bool isComboOpen
+ {
+ get
+ {
+ return owner.unitAnimation.baseLayer.IsToggleOpen(EAnimationToogle.Combo);
+ }
+ }
} \ No newline at end of file