123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using UnityEngine;
- namespace Animancer.FSM
- {
- public partial class StateMachine<TState>
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class InputBuffer : InputBuffer<StateMachine<TState>>
- {
-
-
- public InputBuffer() { }
-
- public InputBuffer(StateMachine<TState> stateMachine) : base(stateMachine) { }
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class InputBuffer<TStateMachine> where TStateMachine : StateMachine<TState>
- {
-
- private TStateMachine _StateMachine;
-
- public TStateMachine StateMachine
- {
- get => _StateMachine;
- set
- {
- _StateMachine = value;
- Clear();
- }
- }
-
- public TState State { get; set; }
-
- public float TimeOut { get; set; }
-
-
- public bool IsActive => State != null;
-
-
- public InputBuffer() { }
-
- public InputBuffer(TStateMachine stateMachine) => _StateMachine = stateMachine;
-
-
-
- public void Buffer(TState state, float timeOut)
- {
- State = state;
- TimeOut = timeOut;
- }
-
-
- protected virtual bool TryEnterState() => StateMachine.TryResetState(State);
-
-
-
- public bool Update() => Update(Time.deltaTime);
-
-
-
-
-
- public bool Update(float deltaTime)
- {
- if (IsActive)
- {
- if (TryEnterState())
- {
- Clear();
- return true;
- }
- else
- {
- TimeOut -= deltaTime;
- if (TimeOut < 0)
- Clear();
- }
- }
- return false;
- }
-
-
- public virtual void Clear()
- {
- State = null;
- TimeOut = default;
- }
-
- }
- }
- }
|