/// <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); } }
private void RunEntrances(PluggableStateMachineController stateMachine) { foreach (StateAction action in actions) { action.Entrance(stateMachine); } }
/// <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); } }
/// <summary> /// Does the logic for when the action ends. /// These methods do not need to be overriden. /// </summary> public virtual void Exit(PluggableStateMachineController statemachine) { }
/// <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; }
public override bool Decide(PluggableStateMachineController stateMachine) { var commandReceived = HasReceivedHorizontalCommand(stateMachine); return(commandReceived); }
public override void Perform(PluggableStateMachineController statemachine) { MoveUp(statemachine); }
private void MoveUp(PluggableStateMachineController statemachine) { statemachine.Player.movementVector.y = statemachine.Player.CharacterData.jumpHeight; }
/// <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); }
public void OnEnter(PluggableStateMachineController stateMachine) => RunEntrances(stateMachine);
public abstract bool Decide(PluggableStateMachineController stateMachine);
public override bool Decide(PluggableStateMachineController stateMachine) { return(EvaluateTime()); }
private bool HasReceivedHorizontalCommand(PluggableStateMachineController stateMachine) { return(stateMachine.Player.MovementInput.x != 0); }
public override bool Decide(PluggableStateMachineController stateMachine) => IsGrounded(stateMachine);
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); }
public override void Perform(PluggableStateMachineController statemachine) { throw new System.NotImplementedException(); }
public override void Perform(PluggableStateMachineController controller) { Idle(); }