57 lines
1.1 KiB
C#
57 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public struct BufferedInput
|
|
{
|
|
public BufferedInput( float bufferTime )
|
|
{
|
|
_bufferTime = bufferTime;
|
|
_value = false;
|
|
_timeSincePress = 0f;
|
|
_timeSinceRelease = 0f;
|
|
}
|
|
|
|
private float _bufferTime;
|
|
private bool _value;
|
|
private float _timeSinceRelease;
|
|
private float _timeSincePress;
|
|
|
|
public void Set( bool newValue )
|
|
{
|
|
if ( newValue && !_value )
|
|
{
|
|
_timeSincePress = 0f;
|
|
_timeSinceRelease = 0f;
|
|
}
|
|
|
|
_value = newValue;
|
|
}
|
|
|
|
public void Update( float deltaTime )
|
|
{
|
|
if ( !_value )
|
|
{
|
|
_timeSinceRelease += deltaTime;
|
|
}
|
|
|
|
_timeSincePress += deltaTime;
|
|
}
|
|
|
|
public bool GetValue()
|
|
{
|
|
return _value || _timeSinceRelease <= _bufferTime;
|
|
}
|
|
|
|
public bool GetDown()
|
|
{
|
|
return _value && _timeSincePress <= _bufferTime;
|
|
}
|
|
|
|
public bool GetRelease()
|
|
{
|
|
return !_value && _timeSinceRelease < _bufferTime;
|
|
}
|
|
}
|