Files
Cielonos/Assets/Scripts/SLSFramework/General/CompoundVariable.cs
SoulliesOfficial ef7b479712 initial
2025-11-25 08:19:33 -05:00

50 lines
1.2 KiB
C#

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;
}
}
}