void ChangeState(State newState) { switch (currentState) { case State.INITIAL: break; case State.ENTER: RouterExecutor.Exit(); RouterExecutor.target = null; RouterExecutor.enabled = false; break; case State.MAKE_POO: break; case State.EXIT: RouterExecutor.Exit(); RouterExecutor.target = null; RouterExecutor.enabled = false; break; } switch (newState) { case State.INITIAL: break; case State.ENTER: RouterExecutor.ReEnter(); RouterExecutor.target = GOTarjet; RouterExecutor.enabled = true; break; case State.MAKE_POO: break; case State.EXIT: RouterExecutor.ReEnter(); RouterExecutor.target = GOTarjet; RouterExecutor.enabled = true; break; } currentState = newState; }
void ChangeState(State newState) { //EXIT STATE LOGIC switch (currentState) { case State.WANDER: fsm_Wander.Exit(); fsm_Wander.enabled = false; break; case State.SEED: fsm_Seed.Exit(); fsm_Seed.enabled = false; break; case State.GO_TO_ENERGY_POINT: fsm_RouteExec.Exit(); fsm_RouteExec.enabled = false; energyPoint = null; break; case State.RECHARGE: break; } //ENTER STATE LOGIC switch (newState) { case State.WANDER: fsm_Wander.enabled = true; fsm_Wander.ReEnter(); break; case State.SEED: fsm_Seed.enabled = true; fsm_Seed.ReEnter(); break; case State.GO_TO_ENERGY_POINT: myBlackBoard.memory.Clear(); FindNearestRechargePoint(); //FIND THE NEAREST CHARGE POINT fsm_RouteExec.ReEnter(); fsm_RouteExec.target = energyPoint; fsm_RouteExec.enabled = true; //ENABLE ROUTEEXECUTOR_FSM break; case State.RECHARGE: break; } currentState = newState; }
void ChangeState(State newState) { //Exit switch (currentState) { case State.INITIAL: break; case State.NORAMAL: FSMMOuse.Exit(); FSMMOuse.enabled = false; break; case State.FLEE: RouterExecutor.Exit(); RouterExecutor.target = null; RouterExecutor.enabled = false; break; } //enter switch (newState) { case State.INITIAL: break; case State.NORAMAL: FSMMOuse.ReEnter(); FSMMOuse.enabled = true; break; case State.FLEE: RouterExecutor.ReEnter(); RouterExecutor.target = OBTarget; RouterExecutor.enabled = true; mySpriteRenderer.color = Color.green; break; } currentState = newState; }
void Update() { switch (currentState) { case State.INITIAL: ChangeState(State.PIVOT_STATE); break; case State.SEED_POO: GameObject otherPoo; otherPoo = SensingUtils.FindInstanceWithinRadius(gameObject, "POO", myBlackBoard.farPooDetectionRadius); if (otherPoo != null && !otherPoo.Equals(targetedPoo)) { if (DistanceFromMe(otherPoo) < DistanceFromMe(targetedPoo)) { targetedPoo = otherPoo; fsm_RouteExec.Exit(); fsm_RouteExec.ReEnter(); fsm_RouteExec.target = otherPoo; } } if (targetedPoo != null && CheckIfDustInCloseRange() || CheckIfDustInLargeRange()) { /*GameObject dustOnTheWay; * dustOnTheWay = SensingUtils.FindInstanceWithinRadius(gameObject, "DUST", myBlackBoard.closeDustDetectionRadius); * if (dustOnTheWay != null) * { * if (!CheckIfDustIsInMemory(dustOnTheWay)) * { * myBlackBoard.AddToMemory(dustOnTheWay); * } * }*/ if (CheckIfDustInCloseRange()) { myBlackBoard.AddToMemory(targetedDust); targetedDust = null; } if (CheckIfDustInLargeRange()) { myBlackBoard.AddToMemory(targetedDust); targetedDust = null; } } if (targetedPoo != null && DistanceFromMe(targetedPoo) < myBlackBoard.pooReachedRadius) { CleanUp(targetedPoo); ChangeState(State.PIVOT_STATE); break; } break; case State.PIVOT_STATE: if (CheckIfPooInCloseRange() || CheckIfPooInLargeRange()) { ChangeState(State.SEED_POO); break; } else if (myBlackBoard.memory.Count > 0) { ChangeState(State.SEED_DUST_IN_MEMORY); break; } else if (CheckIfDustInCloseRange()) { ChangeState(State.SEED_DUST); break; } else if (CheckIfDustInLargeRange()) { ChangeState(State.SEED_DUST); break; } else { } break; case State.SEED_DUST: if (CheckIfPooInCloseRange() || CheckIfPooInLargeRange() && DistanceFromMe(targetedDust) > myBlackBoard.dustReachedRadius) { targetedDust = null; ChangeState(State.SEED_POO); break; } GameObject otherDust; otherDust = SensingUtils.FindInstanceWithinRadius(gameObject, "DUST", myBlackBoard.closeDustDetectionRadius); if (otherDust != null && !otherDust.Equals(targetedDust)) { if (DistanceFromMe(otherDust) < DistanceFromMe(targetedDust)) { targetedDust = otherDust; fsm_RouteExec.Exit(); fsm_RouteExec.ReEnter(); fsm_RouteExec.target = otherDust; } } if (targetedDust != null && DistanceFromMe(targetedDust) < myBlackBoard.dustReachedRadius) { CleanUp(targetedDust); ChangeState(State.PIVOT_STATE); break; } break; case State.SEED_DUST_IN_MEMORY: if (nearestDust != null && DistanceFromMe(nearestDust) < myBlackBoard.dustReachedRadius) { RemoveDustFromMemory(nearestDust); CleanUp(nearestDust); if (myBlackBoard.memory.Count > 0) { ChangeState(State.SEED_DUST_IN_MEMORY); break; } else { ChangeState(State.PIVOT_STATE); break; } } break; } }