Exemplo n.º 1
0
 /// <summary>
 /// Executes all the actions for the state.
 /// </summary>
 /// <param name="controller">Reference to the controller.</param>
 private void PerformActions(PluggableStateMachineController stateMachine)
 {
     foreach (StateAction v in actions)
     {
         v.Perform(stateMachine);
     }
 }
Exemplo n.º 2
0
 private void RunEntrances(PluggableStateMachineController stateMachine)
 {
     foreach (StateAction action in actions)
     {
         action.Entrance(stateMachine);
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// Checks to see if the state machine should remain
    /// in this state or moves to the next one.
    /// </summary>
    /// <param name="stateMachine">StateMachine controller</param>
    private void CheckTransitions(PluggableStateMachineController stateMachine)
    {
        foreach (Transition transition in transitions)
        {
            var decisions = transition.decisions;
            var success   = false;
            foreach (var decision in decisions)
            {
                var decisionSucceeded = decision.Decide(stateMachine);
                success = decisionSucceeded;
                if (!decisionSucceeded)
                {
                    break;
                }
            }

            var nextState = success
                ? transition.trueState
                : transition.falseState;

            stateMachine.TransitionToState(nextState);
        }
    }
Exemplo n.º 4
0
 /// <summary>
 /// Does the logic for when the action ends.
 /// These methods do not need to be overriden.
 /// </summary>
 public virtual void Exit(PluggableStateMachineController statemachine)
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Does the logic for this action.
 /// Required to be overriden.
 /// </summary>
 public abstract void Perform(PluggableStateMachineController statemachine);
 public override void Perform(PluggableStateMachineController controller)
 {
     ApplyMovement(controller);
 }
 private void ApplyMovement(PluggableStateMachineController stateMachine)
 {
     stateMachine.CharacterController.Move(stateMachine.Player.movementVector * Time.deltaTime, false);
 }
 // Create a virtual input manager like Roundbear?
 // Link: https://www.youtube.com/watch?v=HVwss7AFfaA&list=PLWYGofN_jX5BupV2xLjU1HUvujl_yDIN6&index=15
 // This is interesting, because this solves the problem of creating
 // a whole separate slew of Actions/States/Transitions/Conditions.
 // There only has to be one predefined number of actions, anyone can
 // do and you just have to give them the option.
 // Pig Chef solution
 // Update the parameters of the movement script / input controlling script
 // Example, this class can have access to the CharacterController.InputScript
 // Then it can set values from that script CharacterController.InputScript.MovementVector.y = 3f;
 // And this doesn't have to worry about calling in a Function like Move(parm1, parma2, param3)
 private void MoveFoward(PluggableStateMachineController stateMachine)
 {
     stateMachine.Player.movementVector.x = stateMachine.Player.CharacterData.moveSpeed * stateMachine.Player.MovementInput.x;
 }
 private void ApplyGravity(PluggableStateMachineController controller)
 {
     controller.Player.movementVector.y = -gravity;
 }
Exemplo n.º 10
0
    public override bool Decide(PluggableStateMachineController stateMachine)
    {
        var commandReceived = HasReceivedHorizontalCommand(stateMachine);

        return(commandReceived);
    }
Exemplo n.º 11
0
 public override void Perform(PluggableStateMachineController statemachine)
 {
     MoveUp(statemachine);
 }
Exemplo n.º 12
0
 private void MoveUp(PluggableStateMachineController statemachine)
 {
     statemachine.Player.movementVector.y = statemachine.Player.CharacterData.jumpHeight;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Calls logic for this state in the game loop.
 /// </summary>
 /// <param name="controller">Reference to the controller.</param>
 public void UpdateState(PluggableStateMachineController stateMachine)
 {
     PerformActions(stateMachine);
     CheckTransitions(stateMachine);
 }
Exemplo n.º 14
0
 public void OnEnter(PluggableStateMachineController stateMachine) => RunEntrances(stateMachine);
Exemplo n.º 15
0
 public abstract bool Decide(PluggableStateMachineController stateMachine);
Exemplo n.º 16
0
 public override bool Decide(PluggableStateMachineController stateMachine)
 {
     return(EvaluateTime());
 }
Exemplo n.º 17
0
 private bool HasReceivedHorizontalCommand(PluggableStateMachineController stateMachine)
 {
     return(stateMachine.Player.MovementInput.x != 0);
 }
 public override bool Decide(PluggableStateMachineController stateMachine) => IsGrounded(stateMachine);
Exemplo n.º 19
0
 public float gravity; // TODO: Make this a float reference
 public override void Perform(PluggableStateMachineController controller)
 {
     ApplyGravity(controller);
 }
 private bool IsGrounded(PluggableStateMachineController stateMachine)
 {
     return(stateMachine.CharacterController.CollisionInfo.Below);
 }
Exemplo n.º 21
0
 public override void Perform(PluggableStateMachineController statemachine)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 22
0
 public override void Perform(PluggableStateMachineController controller)
 {
     Idle();
 }