예제 #1
0
 void OnStateChange(SM.State state, SM.State nextState)
 {
     Debug.Log("OnStateChange: " + nextState);
     if (nextState == SM.State.Grounded)
     {
         Debug.Log("Resetting force");
         m_force.y = 0f;
         Debug.Log("force: " + m_force);
     }
 }
예제 #2
0
    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();
    }