StateMachine<TState>.

StateMachine<TState>.InputBuffer<TStateMachine> Class

Summary

A simple system that can Animancer.FSM.StateMachine`1.InputBuffer`1.Buffer(`0,System.Single) a state then try to enter it every time Animancer.FSM.StateMachine`1.InputBuffer`1.Update(System.Single) is called until the Animancer.FSM.StateMachine`1.InputBuffer`1.TimeOut expires.
graph BT Type-->Base0["Object"] Type["StateMachine<TState>.InputBuffer<TStateMachine>"] class Type type-node Derived0["StateMachine<TState>.InputBuffer"]-->Type click Derived0 "/animancer/api/Animancer.FSM/InputBuffer" Derived1["StateMachine<TKey, TState>.InputBuffer"]-->Type click Derived1 "/animancer/api/Animancer.FSM/InputBuffer"

Syntax

public class StateMachine<TState>.InputBuffer<TStateMachine> 
    where TStateMachine : StateMachine<TState>

Examples

public StateMachine<CharacterState> stateMachine;// Initialized elsewhere.

[SerializeField] private CharacterState _Attack;
[SerializeField] private float _AttackInputTimeOut = 0.5f;

private StateMachine<CharacterState>.InputBuffer _InputBuffer;

private void Awake()
{
    // Initialize the buffer.
    _InputBuffer = new StateMachine<CharacterState>.InputBuffer(stateMachine);
}

private void Update()
{
    // When input is detected, buffer the desired state.
    if (Input.GetButtonDown("Fire1"))// Left Click by default.
    {
        _InputBuffer.Buffer(_Attack, _AttackInputTimeOut);
    }

    // At the end of the frame, Update the buffer so it tries to enter the buffered state.
    // After the time out, it will clear itself so Update does nothing until something else is buffered.
    _InputBuffer.Update();
}

Remarks

Documentation: Input Buffers

Type Parameters

Name Description
TStateMachine

Constructors

Name Summary
InputBuffer() Creates a new Animancer.FSM.StateMachine`1.InputBuffer`1.
InputBuffer(TStateMachine) Creates a new Animancer.FSM.StateMachine`1.InputBuffer`1 for the specified `stateMachine`.

Properties

Name Value Summary
IsActive bool
Is this buffer currently trying to enter a Animancer.FSM.StateMachine`1.InputBuffer`1.State?
State TState
The TState this buffer is currently attempting to enter.
StateMachine TStateMachine
The Animancer.FSM.StateMachine`1 this buffer is feeding input to.
TimeOut float
The amount of time left before the Animancer.FSM.StateMachine`1.InputBuffer`1.State is cleared.

Methods

Name Value Summary
Buffer(TState, float) void
Sets the Animancer.FSM.StateMachine`1.InputBuffer`1.State and Animancer.FSM.StateMachine`1.InputBuffer`1.TimeOut.
Clear() void
Clears this buffer so it stops trying to enter the Animancer.FSM.StateMachine`1.InputBuffer`1.State.
TryEnterState() bool
Attempts to enter the Animancer.FSM.StateMachine`1.InputBuffer`1.State and returns true if successful.
Update() bool
Calls Animancer.FSM.StateMachine`1.InputBuffer`1.Update(System.Single) using UnityEngine.Time.deltaTime.
Update(float) bool
Attempts to enter the Animancer.FSM.StateMachine`1.InputBuffer`1.State if there is one and returns true if successful. Otherwise the Animancer.FSM.StateMachine`1.InputBuffer`1.TimeOut is decreased by `deltaTime` and Animancer.FSM.StateMachine`1.InputBuffer`1.Clear is called if it reaches 0.