/// <summary> /// 把想要註冊的狀態一個個加進來~ /// </summary> void AddState() { SubscribeStateLibrary.Add("Idle", new ChuChuIdleToRun()); SubscribeStateLibrary.Add("JumpStart", new ChuChuJumpStart()); SubscribeStateLibrary.Add("JumpLoop", new ChuChuJumpLoop()); SubscribeStateLibrary.Add("JumpEnd", new ChuChuJumpEnd()); SubscribeStateLibrary.Add("LeftGetHit", new ChuChuLeftGetHit()); SubscribeStateLibrary.Add("FrontGetHit", new ChuChuFrontGetHit()); SubscribeStateLibrary.Add("RightGetHit", new ChuChuRightGetHit()); SubscribeStateLibrary.Add("Dead", new ChuChuDead()); SubscribeStateLibrary.Add("Down", new ChuChuDown()); SubscribeStateLibrary.Add("Up", new ChuChuUp()); SubscribeStateLibrary.Add("Dash", new ChuChuDash()); SubscribeStateLibrary.Add("R1", new ChuChuR1()); SubscribeStateLibrary.Add("R1R1", new ChuChuR1R1()); SubscribeStateLibrary.Add("R1R1R1", new ChuChuR1R1R1()); SubscribeStateLibrary.Add("R1R1R1R1", new ChuChuR1R1R1R1()); SubscribeStateLibrary.Add("R1R1R1R1R1", new ChuChuR1R1R1R1R1()); SubscribeStateLibrary.Add("R1R2", new ChuChuR1R2()); SubscribeStateLibrary.Add("R1R1R2", new ChuChuR1R1R2()); SubscribeStateLibrary.Add("R2R2R2R2", new ChuChuR2R2R2R2()); SubscribeStateLibrary.Add("R2", new ChuChuR2()); SubscribeStateLibrary.Add("R2R2", new ChuChuR2R2()); SubscribeStateLibrary.Add("R2R2R2", new ChuChuR2R2R2()); }
/// <summary> /// 轉換狀態 /// </summary> /// <param name="_state"></param> /// <returns></returns> IEnumerator Transit(string _state) { if (SubscribeStateLibrary.ContainsKey(sNextState)) //防呆!如果沒有註冊該狀態跳Log { AnimPlayer.SetBool(sCurrentState, false); //(Animator)把原本進這狀態的transition關上 LeaveCurrentState(SubscribeStateLibrary[sCurrentState]); //執行Leave sCurrentState = sNextState; //目前狀態->新的狀態 sNextState = null; //把排隊的位置清掉 bAllowTransit = false; //新的狀態即重新計算可轉換的時機 AnimPlayer.SetBool(sCurrentState, true); //(Animator)打開前往下一個狀態的transition TransitCurrentState(SubscribeStateLibrary[sCurrentState]); //執行Transit StartCoroutine(InputController()); //從轉換開始當下已開始跑下一狀態的動作,因此剛轉換呼叫為準 } else { Debug.Log("An accidental state be called !"); //防呆!如果沒有註冊該狀態跳Log } yield return(new WaitUntil(() => AnimPlayer.IsInTransition(0) == false)); //(Animator)等,直到動作切換結束 EnterCurrentState(SubscribeStateLibrary[sCurrentState]); //轉換結束後呼叫Enter該狀態改變規範 }