public AIFSM(string name, EnemyController controller) : base(name, controller) { if (!controller) { // TODO: Add log LogHalt("EnemyController object null!"); Halt(); } #if UNITY_EDITOR LogThis = true; #endif idleState = new IdleState(this, EAIState.IDLE, "STATE_IDLE", controller); alertState = new AlertState(this, EAIState.ALERT, "STATE_ALERT", controller); aggressiveState = new AggressiveState(this, EAIState.AGGRESSIVE, "STATE_AGGRESSIVE", controller); idleState.AddTransition(new Tran_IdleToAlert(alertState, controller)); alertState.AddTransition(new Tran_AlertToAggressive(aggressiveState, controller)); alertState.AddTransition(new Tran_AlertToIdle(idleState, controller)); aggressiveState.AddTransition(new Tran_AggressiveToAlert(alertState, controller)); AddState(idleState); AddState(alertState); AddState(aggressiveState); }
void Awake() { // state machine setup CollisionNotifier collisionNotifier = transform.Find("Sphere").GetComponent <CollisionNotifier>(); stateMachine = new InputStateMachine(); NormalState normalState = new NormalState(this, wanderStrength, collisionNotifier); stateMachine.AddState(normalState); AggressiveState aggressiveState = new AggressiveState(this, wanderStrength, guidePointDistance, aggressiveTime, collisionNotifier); stateMachine.AddState(aggressiveState); stateMachine.ChangeToState <NormalState>(); // decision tree setup treeRoot = new DecisionQuery <AIInput, Path> { Test = (ai) => ai.currentPath.CheckIfOnCriticalSection(ai.car.position), Positive = new DecisionResult <AIInput, Path>(null), Negative = new DecisionQuery <AIInput, Path> { Test = (ai) => ai.behaviour.boostCount < ai.minBoost, Positive = new DecisionResult <AIInput, Path>(coinPath), Negative = new DecisionQuery <AIInput, Path> { Test = (ai) => ai.otherCar.boostCount > ai.behaviour.boostCount, Positive = new DecisionResult <AIInput, Path>(coinPath), Negative = new DecisionResult <AIInput, Path>(fastPath) } } }; }