From cf4e1f9833c810e18429ddf40f4bcf9052ff17ac Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 29 Aug 2021 19:44:31 +0800 Subject: *monster --- Assets/Scripts/Unit/Component/UnitState.cs | 423 +---------------------------- 1 file changed, 1 insertion(+), 422 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 1de97901..2825f606 100644 --- a/Assets/Scripts/Unit/Component/UnitState.cs +++ b/Assets/Scripts/Unit/Component/UnitState.cs @@ -8,426 +8,5 @@ using UnityEngine; [DisallowMultipleComponent] public class UnitState : UnitComponent { - public enum EUnitState - { - Nien, - Idle , - Move , - Spawn , - Die , - Dead , - // - Attack , - AirAttack , - AirDash , - // - HitAir , - HitAirHit , - Knockdown , - // - HitGuard , - // - Walk , - // - Rise , - // - Jump , - // 转身 - Turn , - Landing , // 从空中降落 - } - - [SerializeField] private EUnitState m_State; - public EUnitState CurrentState { get { return m_State; } } - - public override void Initialize() - { - base.Initialize(); - - InitState(); - } - - UnitAnimation unitAnimation { get { return m_Owner.unitAnimation; } } - - #region state param - public struct IdleParam {} - - public struct MoveParam - { - public bool isRight; - public string key; - } - - public struct SkillParam - { - - } - - public struct AirDashParam - { - - } - - public struct JumpParam - { } - - public struct TurnParam - { - EUnitState nextState; - } - - public struct LandingParam { } - - #endregion - - void InitState() - { - } - - public void ChangeState(EUnitState nextState, T param = default, bool bForce = false) - { - if (!IsChange(nextState, bForce)) - return; - - LogHelper.Log("UnitState: " + m_State.ToString() + " -> " + nextState.ToString()); - - 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) - { - exitMethod.Invoke(this, new object[] { nextState }); - } - else - { - LogHelper.LogError("缺少 " + methodFunc); - } - m_State = nextState; - - StartCoroutine(m_State.ToString(), param); - } - - bool IsChange(EUnitState newState, bool bForce) - { - if (newState != m_State || bForce) - return true; - 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); - } - - public void TurnLeft() - { - TurnAround(false); - } - - 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.unitAnimation.AnimIdle(); - while (true) - { - //if (Input.GetKeyDown("j")) - //{ - // ChangeState(EUnitState.Attack, new SkillParam()); - //} - if (Input.GetKeyDown("space")) - { - ChangeState(EUnitState.Jump, new JumpParam()); - } - if (Input.GetKey("d")) - { - InputManager.Instance.OnMoveRight(); - } - if (Input.GetKey("a")) - { - InputManager.Instance.OnMoveLeft(); - } - 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.unitAnimation.Play(UnitAnimation.EAnimState.Turn); - //yield return new WaitForActionReachEnd(m_Owner.unitAnimation); - //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.unitAnimation.AnimMove(); - while (Input.GetKey(param.key)) - { - yield return null; - } - ChangeState(EUnitState.Idle, new IdleParam()); - } - - void OnMoveExit(EUnitState nextState) - { - m_Owner.unitAnimation.animator.ResetTrigger("ToMove"); - } - - #endregion - - #region Attack - - IEnumerator Attack(SkillParam param) - { - while(true) - { - - - yield return null; - } - } - - void OnAttackExit(EUnitState next) - { - - } - - #endregion - - #region AirAttack - - IEnumerator AirAttack(SkillParam param) - { - int id = 0; - m_Owner.unitAnimation.AnimAirAttack(id); - yield return null; // 等待animator更新 - while (true) - { - 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) - { - ChangeState(EUnitState.Landing, new LandingParam()); - } - - yield return null; - } - } - - void OnAirAttackExit(EUnitState next) - { - - } - - #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 - - IEnumerator Jump(JumpParam param) - { - unitAnimation.AnimJump(); - yield return null; - yield return new WaitForTransitionDone(unitAnimation); - 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 (unitAnimation.layers[0].playbackNomralizedTime >= 1) - ChangeState(EUnitState.Idle, new IdleParam()); - bool canAttack = m_Owner.unitAnimation.layers[0].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.unitAnimation.AnimLanding(); - yield return null; - yield return new WaitForTransitionDone(m_Owner.unitAnimation); - 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; - } - m_Owner.transform.position = pos; - if (pos.y > 0 && pos.y <= 1 && !landingGround) - { - landingGround = true; - m_Owner.unitAnimation.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 OnLandingExit(EUnitState next) - { - } - - #endregion - -} +} \ No newline at end of file -- cgit v1.1-26-g67d0