2018-10-30 15:05:06 -04:00
|
|
|
namespace UnityAtoms
|
|
|
|
{
|
2019-10-15 16:02:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// None generic base class for `AtomReference<T, V>`.
|
|
|
|
/// </summary>
|
2019-09-25 15:05:06 -04:00
|
|
|
public abstract class AtomReference { }
|
2019-04-17 07:05:23 -04:00
|
|
|
|
2019-09-25 15:05:06 -04:00
|
|
|
public abstract class AtomReference<T, V> : AtomReference
|
2019-09-30 16:55:33 -04:00
|
|
|
where V : AtomBaseVariable<T>
|
2018-10-30 15:05:06 -04:00
|
|
|
{
|
2019-10-15 16:02:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// If set to `true` then use constant instead of Variable value.
|
|
|
|
/// </summary>
|
2019-04-07 10:03:16 -04:00
|
|
|
public bool UseConstant;
|
|
|
|
|
2019-10-15 16:02:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Constant value used if `UseConstant` is set to `true`.
|
|
|
|
/// </summary>
|
2018-10-30 15:05:06 -04:00
|
|
|
public T ConstantValue;
|
|
|
|
|
2019-10-15 16:02:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Variable used if `UseConstant` is set to `false`.
|
|
|
|
/// </summary>
|
2019-04-07 10:03:16 -04:00
|
|
|
public V Variable;
|
2018-10-30 15:05:06 -04:00
|
|
|
|
2019-09-25 15:05:06 -04:00
|
|
|
protected AtomReference()
|
2018-10-30 15:05:06 -04:00
|
|
|
{
|
|
|
|
UseConstant = true;
|
2019-04-07 10:03:16 -04:00
|
|
|
}
|
|
|
|
|
2019-09-25 15:05:06 -04:00
|
|
|
protected AtomReference(T value) : this()
|
2019-04-07 10:03:16 -04:00
|
|
|
{
|
2019-04-08 10:14:50 -04:00
|
|
|
UseConstant = true;
|
2018-10-30 15:05:06 -04:00
|
|
|
ConstantValue = value;
|
|
|
|
}
|
|
|
|
|
2019-10-15 16:02:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Get the value for the Reference.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The value of type `T`.</value>
|
2018-10-30 15:05:06 -04:00
|
|
|
public T Value
|
|
|
|
{
|
|
|
|
get { return UseConstant ? ConstantValue : Variable.Value; }
|
|
|
|
}
|
|
|
|
|
2019-09-25 15:05:06 -04:00
|
|
|
public static implicit operator T(AtomReference<T, V> reference)
|
2018-10-30 15:05:06 -04:00
|
|
|
{
|
|
|
|
return reference.Value;
|
|
|
|
}
|
|
|
|
}
|
2019-04-07 05:10:09 -04:00
|
|
|
}
|