void setFSM() { _fsm = new FSMBeetle(); _fsm.beetle = this; _fsm.beetleFlocking = _flocking; _fsm.beetleLineOfSight = _lineOfSight; patrolling = new StatePatrolling(_fsm); wander = new StateWander(_fsm); lostSquirrel = new StateLostSquirrel(_fsm); chasingSound = new StateChasingSound(_fsm); seekingSquirrel = new StateSeekingSquirrel(_fsm); //patrolling patrolling.transitions[InputBeetle.InSight] = seekingSquirrel; patrolling.transitions[InputBeetle.SoundHearded] = chasingSound; //seekingSquirrel seekingSquirrel.transitions[InputBeetle.LostSight] = lostSquirrel; //lostSquirrel lostSquirrel.transitions[InputBeetle.ReachedPosition] = wander; //wander wander.transitions[InputBeetle.InSight] = seekingSquirrel; wander.transitions[InputBeetle.SoundHearded] = chasingSound; wander.transitions[InputBeetle.finishedWandering] = patrolling; //chasingSound chasingSound.transitions[InputBeetle.ReachedPosition] = wander; chasingSound.transitions[InputBeetle.InSight] = seekingSquirrel; _fsm.SetInitial(patrolling); }
public void Start() { // Creates Transitions Transition startMining = new TransitionStartMining(gameObject); Transition stopMining = new TransitionStopMining(); Transition startWait = new TransitionStartWait(gameObject); Transition stopWait = new TransitionStopWait(gameObject); Transition alerted = new TransitionAlerted(gameObject); Transition wakeUp = new TransitionWakeUp(gameObject); Transition sleep = new TransitionSleep(gameObject); Transition goToSleep = new TransitionGoToSleep(gameObject); Transition backToMining = new TransitionBackToMining(gameObject); walkToMineTrans.Add(startMining); walkToMineTrans.Add(alerted); miningTrans.Add(stopMining); miningTrans.Add(alerted); walkToChestTrans.Add(startWait); walkToChestTrans.Add(alerted); waitingTrans.Add(stopWait); waitingTrans.Add(alerted); hidingTrans.Add(backToMining); sleepingTrans.Add(wakeUp); walkingTrans.Add(sleep); wanderTrans.Add(goToSleep); // Creates States StateWalkToChest walkToChest = new StateWalkToChest(gameObject, walkToChestTrans); StateMining mining = new StateMining(gameObject, miningTrans, "Mining"); StateWaiting waiting = new StateWaiting(gameObject, waitingTrans, "Waiting"); StateHiding hiding = new StateHiding(gameObject, hidingTrans); StateWaiting sleeping = new StateWaiting(gameObject, sleepingTrans, "Sleeping"); StateWander wander = new StateWander(gameObject, wanderTrans); StateWaiting walking = new StateWaiting(gameObject, walkingTrans, "Walking"); if (Object.Equals(gameObject.name, "Miner (iron)")) { StateWalkToMine ironMiner = new StateWalkToMine(gameObject, gameObject.GetComponent <pathFind>().graph, "OreIron", walkToMineTrans); initialState = ironMiner; states.Add(ironMiner); states.Add(walkToChest); states.Add(mining); states.Add(waiting); states.Add(hiding); } else if (Object.Equals(gameObject.name, "Miner (gold)")) { StateWalkToMine goldMiner = new StateWalkToMine(gameObject, gameObject.GetComponent <pathFind>().graph, "OreGold", walkToMineTrans); initialState = goldMiner; states.Add(goldMiner); states.Add(walkToChest); states.Add(mining); states.Add(waiting); states.Add(hiding); } else if (Object.Equals(gameObject.name, "Miner (diamond)")) { StateWalkToMine diamondMiner = new StateWalkToMine(gameObject, gameObject.GetComponent <pathFind>().graph, "OreDiamond", walkToMineTrans); initialState = diamondMiner; states.Add(diamondMiner); states.Add(walkToChest); states.Add(mining); states.Add(waiting); states.Add(hiding); } else if (Object.Equals(gameObject.name, "Monster")) { initialState = sleeping; states.Add(sleeping); states.Add(wander); states.Add(walking); } currentState = initialState; }