整合SLSUtilities
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace SLSFramework.General
|
||||
{
|
||||
public class CompoundVariable<T>
|
||||
{
|
||||
public int trueCount;
|
||||
private T positiveValue;
|
||||
private T zeroAndNegativeValue;
|
||||
public T value => trueCount > 0 ? positiveValue : zeroAndNegativeValue;
|
||||
|
||||
public CompoundVariable(bool reverse = false)
|
||||
{
|
||||
if (typeof(T) == typeof(bool))
|
||||
{
|
||||
positiveValue = (T)(object)true;
|
||||
zeroAndNegativeValue = (T)(object)false;
|
||||
trueCount = reverse ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.Exception("CompoundVariable default constructor only supports bool type.");
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundVariable(T positiveValue, T zeroAndNegativeValue)
|
||||
{
|
||||
this.positiveValue = positiveValue;
|
||||
this.zeroAndNegativeValue = zeroAndNegativeValue;
|
||||
trueCount = 0;
|
||||
}
|
||||
|
||||
public void Modify(bool marker)
|
||||
{
|
||||
if (marker)
|
||||
{
|
||||
trueCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
trueCount--;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
trueCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user