void Start() { fsm = new FSM("Tower AI"); // Create AttackState attackState = fsm.AddState("AttackState"); attackAction = new Attack(gameObject, attackState); // Create IdleState idleState = fsm.AddState("IdleState"); idleAction = new Idle(gameObject, idleState); // Add actions attackState.AddAction(attackAction); idleState.AddAction(idleAction); // Add events attackState.AddEvent("ToIdle", idleState); idleState.AddEvent("ToAttack", attackState); // Initialize actions attackAction.Start(finishEvent: "ToIdle"); idleAction.Start(finishEvent: "ToAttack"); // Start the fsm fsm.Start("IdleState"); }
public void Once() { this.loop = new Loop(); Idle idle = this.loop.CreateIdle(); idle.Start(this.IdleCallback); while (this.loop.RunOnce() != 0) { Assert.True(idle.IsValid); } Assert.Equal(NumberOfTicks, this.idleCounter); }
public void Run() { this.loop = new Loop(); this.idleCallbackCheck = false; this.timerCallbackCheck = false; this.idleCalled = 0; this.timerCalled = 0; Idle idleStart = this.loop.CreateIdle(); idleStart.Start(this.NextTick); Assert.Equal(0, this.idleCalled); Assert.Equal(0, this.timerCalled); this.loop.RunDefault(); Assert.Equal(1, this.idleCalled); Assert.Equal(1, this.timerCalled); Assert.True(this.timerCallbackCheck); Assert.True(this.idleCallbackCheck); }