void InitFsm() { _fsm = new FSM(); _fsm.SetCurrStateName("Idle"); float remainingTime = 0; _fsm.AddState("Idle"); _fsm.AddState("DelayToMonsterSpawn", () => { remainingTime = delayTime; }, () => { remainingTime -= Time.deltaTime; if (remainingTime <= 0) { _fsm.SendEvent("AllToMonsterSpawn"); } }, () => { }); IEnumerator enumerator = null; _fsm.AddState("MonsterSpawn", () => { int level = 1; if (GameManager.Instance != null && GameManager.Instance.Player1 != null && GameManager.Instance.Player1.RoleData != null) { level = GameManager.Instance.Player1.RoleData.level; } enumerator = Spawn(RoleGroupList[(CurrIndex++) % RoleGroupList.Count].RoleIdList, "2", level); }, () => { bool canNext = enumerator.MoveNext(); RoleController roleController = enumerator.Current as RoleController; if (roleController) { aliveMonsterCount++; roleController.OnDying += RoleDying; } if (!canNext) { _fsm.SendEvent("AllToIdle"); } }, () => { enumerator = null; }); _fsm.AddEvent("IdleToMonsterSpawn", "Idle", "DelayToMonsterSpawn", () => { return(aliveMonsterCount == 0); }); }
//adds an FSM state to show that we are animating private void AddAnimationState() { if (States.Find(k => k.name == "KAS_Animation") == null) { KFSMState state = new KFSMState("KAS_Animation"); state.updateMode = KFSMUpdateMode.MANUAL_TRIGGER; FSM.AddState(state); KFSMEvent enterEvent = new KFSMEvent("Enter KAS_Animation"); enterEvent.GoToStateOnEvent = state; enterEvent.updateMode = KFSMUpdateMode.MANUAL_TRIGGER; var idleGrounded = States.Find(k => k.name == "Idle (Grounded)"); FSM.AddEvent(enterEvent, idleGrounded); KFSMEvent exitEvent = new KFSMEvent("Exit KAS_Animation"); exitEvent.GoToStateOnEvent = idleGrounded; exitEvent.updateMode = KFSMUpdateMode.MANUAL_TRIGGER; FSM.AddEvent(exitEvent, state); } }