private void SetupStateMachine() { // Conditions Condition.BoolCondition IsTeamActiveCondition = new Condition.BoolCondition(IsTeamActive); Condition.NotCondition IsTeamInActiveCondition = new Condition.NotCondition(IsTeamActiveCondition); // Transitions Transition ActivateTeam = new Transition("Activate Team", IsTeamActiveCondition); Transition DeActivateTeam = new Transition("De-Activate Team", IsTeamInActiveCondition); // Sates State Active = new State("Active", new List <Transition>() { DeActivateTeam }, null, new List <Action>() { ActiveUpdate }, null); State InActive = new State("InActive", new List <Transition>() { ActivateTeam }, null, null, null); // Transition Links ActivateTeam.SetTargetState(Active); DeActivateTeam.SetTargetState(InActive); // Create Machine TeamStateMachine = new StateMachine(null, InActive, Active); TeamStateMachine.InitMachine(); }
private void SetUpStateMachine() { // Configure Transistion requiremnts. Condition.BoolCondition ConstructionCondition = new Condition.BoolCondition(HasConstructionFinished); Condition.BoolCondition DestructionCondition = new Condition.BoolCondition(IsBuildingDestroyed); // Create Transitions. SM.Transition ConstructionFinishedTrans = new SM.Transition("Construction Finished", ConstructionCondition, ConstructionFinished); SM.Transition BuildingDestroyedTrans = new SM.Transition("Building Destroyed", DestructionCondition, BuildingDestroyed); // Create States. SM.State UnderConstruction = new SM.State("Under Construction", new List <SM.Transition>() { ConstructionFinishedTrans }, new List <SM.Action>() { BeginConstruction }, new List <SM.Action>() { ConstructionUpdate }, new List <SM.Action>() { }); SM.State Operational = new SM.State("Operational", new List <SM.Transition>() { BuildingDestroyedTrans }, new List <SM.Action>() { BeginOperational }, new List <SM.Action>() { BuildingUpdate }, null); SM.State Destroyed = new SM.State("Destroyed", null, null, new List <SM.Action>() { DestructionUpdate }, null); // Add target state to transitions ConstructionFinishedTrans.SetTargetState(Operational); BuildingDestroyedTrans.SetTargetState(Destroyed); BuildingStateMachine = new SM.StateMachine(null, UnderConstruction, Operational, Destroyed); // Initialise the machine. BuildingStateMachine.InitMachine(); }