// Animancer // Copyright 2020 Kybernetik // namespace Animancer.FSM { public partial class StateMachine { /// /// A simple buffer that remembers any failed calls to /// so that it can retry them each time you /// it until the expires. /// public new class InputBuffer : StateMachine.InputBuffer { /************************************************************************************************************************/ private StateMachine _StateMachine; /// The this buffer is feeding input to. public new StateMachine StateMachine { get { return _StateMachine; } set { _StateMachine = value; base.StateMachine = value; } } /// The of the state this buffer is currently attempting to enter. public TKey BufferedKey { get; set; } /************************************************************************************************************************/ /// /// Constructs a new targeting the specified `stateMachine`. /// public InputBuffer(StateMachine stateMachine) : base(stateMachine) { _StateMachine = stateMachine; BufferedKey = stateMachine.CurrentKey; } /************************************************************************************************************************/ /// /// Attempts to enter the specified state and returns true if successful. /// Otherwise the state is remembered and attempted again every time /// is called. /// public bool TrySetState(TKey key, TState state, float timeOut) { BufferedKey = key; return TrySetState(state, timeOut); } /// /// Attempts to enter the specified state and returns true if successful. /// Otherwise the state is remembered and attempted again every time /// is called. /// public bool TrySetState(TKey key, float timeOut) { TState state; if (_StateMachine.TryGetValue(key, out state)) return TrySetState(key, state, timeOut); else return false; } /************************************************************************************************************************/ /// /// Attempts to enter the and returns true if successful. /// protected override bool TryEnterBufferedState() { return _StateMachine.TrySetState(BufferedKey, BufferedState); } /************************************************************************************************************************/ } } }