// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // namespace Animancer.FSM { public partial class StateMachine { /// /// A simple system that can a state then /// try to enter it every time is /// called until the expires. /// /// /// /// Documentation: Input Buffers /// /// /// See . /// /// https://kybernetik.com.au/animancer/api/Animancer.FSM/InputBuffer /// public new class InputBuffer : InputBuffer> { /************************************************************************************************************************/ /// The of the state this buffer is currently attempting to enter. public TKey Key { get; set; } /************************************************************************************************************************/ /// Creates a new . public InputBuffer() { } /// Creates a new for the specified `stateMachine`. public InputBuffer(StateMachine stateMachine) : base(stateMachine) { } /************************************************************************************************************************/ /// /// If a state is registered with the `key`, this method calls /// and returns true. Otherwise it returns false. /// /// Doesn't actually attempt to enter the state until is called. public bool Buffer(TKey key, float timeOut) { if (StateMachine.TryGetValue(key, out var state)) { Buffer(key, state, timeOut); return true; } else return false; } /// /// Sets the , , and /// . /// /// Doesn't actually attempt to enter the state until is called. public void Buffer(TKey key, TState state, float timeOut) { Key = key; Buffer(state, timeOut); } /************************************************************************************************************************/ /// protected override bool TryEnterState() => StateMachine.TryResetState(Key, State); /************************************************************************************************************************/ /// public override void Clear() { base.Clear(); Key = default; } /************************************************************************************************************************/ } } }