BITKit/Packages/Runtime~/Core/Utility/LimitTimes.cs

45 lines
889 B
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
namespace BITKit
{
[System.Serializable]
public class LimitTimes
{
public LimitTimes()
{
m_current = max;
}
2023-06-29 14:57:11 +08:00
2023-06-05 19:57:17 +08:00
public LimitTimes(int max)
{
this.max = max;
m_current = max;
}
2023-06-29 14:57:11 +08:00
2023-06-05 19:57:17 +08:00
public int max = 8;
2023-06-29 14:57:11 +08:00
private int current
2023-06-05 19:57:17 +08:00
{
get => m_current;
set => m_current = value;
}
2023-06-29 14:57:11 +08:00
private int m_current;
2023-06-05 19:57:17 +08:00
public void Release()
{
current++;
}
2023-06-29 14:57:11 +08:00
public bool AllowOnly => current > 0;
public bool Allow => CanUpdate();
2023-06-05 19:57:17 +08:00
public bool CanUpdate()
{
2023-06-29 14:57:11 +08:00
if (AllowOnly is false) return false;
current--;
return true;
2023-06-05 19:57:17 +08:00
}
public static implicit operator bool(LimitTimes self)
{
return self.CanUpdate();
}
}
}