mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-23 08:38:23 -05:00
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
namespace UnityAtoms
|
|
{
|
|
/// <summary>
|
|
/// None generic base class for `AtomReference<T, V>`.
|
|
/// </summary>
|
|
public abstract class AtomReference { }
|
|
|
|
public abstract class AtomReference<T, V> : AtomReference
|
|
where V : AtomBaseVariable<T>
|
|
{
|
|
/// <summary>
|
|
/// If set to `true` then use constant instead of Variable value.
|
|
/// </summary>
|
|
public bool UseConstant;
|
|
|
|
/// <summary>
|
|
/// Constant value used if `UseConstant` is set to `true`.
|
|
/// </summary>
|
|
public T ConstantValue;
|
|
|
|
/// <summary>
|
|
/// Variable used if `UseConstant` is set to `false`.
|
|
/// </summary>
|
|
public V Variable;
|
|
|
|
protected AtomReference()
|
|
{
|
|
UseConstant = true;
|
|
}
|
|
|
|
protected AtomReference(T value) : this()
|
|
{
|
|
UseConstant = true;
|
|
ConstantValue = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the value for the Reference.
|
|
/// </summary>
|
|
/// <value>The value of type `T`.</value>
|
|
public T Value
|
|
{
|
|
get { return UseConstant ? ConstantValue : Variable.Value; }
|
|
}
|
|
|
|
public static implicit operator T(AtomReference<T, V> reference)
|
|
{
|
|
return reference.Value;
|
|
}
|
|
}
|
|
}
|