unity-atoms/Packages/Core/Runtime/Variables/AtomBaseVariable.cs

77 lines
2.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
2019-10-15 16:21:56 -04:00
/// <summary>
/// None generic base class for Variables. Inherits from `BaseAtom`.
/// </summary>
2019-10-14 10:51:54 -04:00
[EditorIcon("atom-icon-teal")]
2019-10-14 20:16:11 -04:00
public abstract class AtomBaseVariable : BaseAtom
{
2019-10-15 16:21:56 -04:00
/// <summary>
/// The Variable value as an `object`.abstract Beware of boxing! 🥊
/// </summary>
/// <value>The Variable value as an `object`.</value>
public abstract object BaseValue { get; set; }
2019-10-15 16:21:56 -04:00
/// <summary>
/// Abstract method that could be implemented to reset the Variable value.
/// </summary>
2019-10-14 10:39:22 -04:00
public abstract void Reset(bool shouldTriggerEvents = false);
}
2019-10-15 16:21:56 -04:00
/// <summary>
/// Generic base class for Variables. Inherits from `AtomBaseVariable`.
/// </summary>
/// <typeparam name="T">The Variable value type.</typeparam>
2019-10-14 10:51:54 -04:00
[EditorIcon("atom-icon-teal")]
2020-02-22 20:22:39 -05:00
public abstract class AtomBaseVariable<T> : AtomBaseVariable, IEquatable<AtomBaseVariable<T>>
{
2019-10-15 16:21:56 -04:00
/// <summary>
/// The Variable value as an `object`.abstract Beware of boxing! 🥊
/// </summary>
/// <value>The Variable value as an `object`.</value>
public override object BaseValue
{
get
{
return _value;
}
set
{
Value = (T)value;
}
}
2019-10-15 16:21:56 -04:00
/// <summary>
/// The Variable value as a property.
/// </summary>
/// <returns>Get or set the Variable value.</returns>
public virtual T Value { get { return _value; } set { throw new NotImplementedException(); } }
[SerializeField]
2020-03-02 13:36:52 -05:00
protected T _value = default(T);
2019-10-15 16:21:56 -04:00
/// <summary>
/// Determines equality between Variables.
/// </summary>
2020-02-22 20:22:39 -05:00
/// <param name="other">The other Variable to compare.</param>
2019-10-15 16:21:56 -04:00
/// <returns>`true` if they are equal, otherwise `false`.</returns>
2020-02-22 20:22:39 -05:00
public bool Equals(AtomBaseVariable<T> other)
{
2020-02-22 20:22:39 -05:00
return other == this;
}
2019-10-15 16:21:56 -04:00
/// <summary>
/// Not implemented.abstract Throws Exception
/// </summary>
2019-10-14 10:39:22 -04:00
public override void Reset(bool shouldTriggerEvents = false)
{
throw new NotImplementedException();
}
}
}