49 lines
964 B
C#
49 lines
964 B
C#
|
namespace BITKit
|
|||
|
{
|
|||
|
[System.Serializable]
|
|||
|
public class LimitTimes
|
|||
|
{
|
|||
|
public LimitTimes()
|
|||
|
{
|
|||
|
m_current = max;
|
|||
|
}
|
|||
|
|
|||
|
public LimitTimes(int max)
|
|||
|
{
|
|||
|
this.max = max;
|
|||
|
m_current = max;
|
|||
|
}
|
|||
|
|
|||
|
public int max = 8;
|
|||
|
|
|||
|
private int current
|
|||
|
{
|
|||
|
get => m_current;
|
|||
|
set => m_current = value;
|
|||
|
}
|
|||
|
|
|||
|
private int m_current;
|
|||
|
|
|||
|
public void Release()
|
|||
|
{
|
|||
|
current++;
|
|||
|
}
|
|||
|
public void Reset()
|
|||
|
{
|
|||
|
current = max;
|
|||
|
}
|
|||
|
public bool AllowOnly => current > 0;
|
|||
|
public bool Allow => CanUpdate();
|
|||
|
public bool CanUpdate()
|
|||
|
{
|
|||
|
if (AllowOnly is false) return false;
|
|||
|
current--;
|
|||
|
return true;
|
|||
|
}
|
|||
|
public static implicit operator bool(LimitTimes self)
|
|||
|
{
|
|||
|
return self.CanUpdate();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|