soundvision/UnityProject/Assets/Scripts/TemplateLibrary/ChangeObserver.cs
2019-10-01 15:08:35 +02:00

33 lines
No EOL
710 B
C#

using System;
namespace cylvester
{
interface IChangeObserver<T> where T : IComparable<T>
{
T Value { set; }
event Action ValueChanged;
}
public class ChangeObserver<T> : IChangeObserver<T> where T : IComparable<T>
{
private T value_;
public ChangeObserver(T initial)
{
Value = initial;
}
public T Value
{
set
{
if (value.CompareTo(value_) == 0)
return;
value_ = value;
ValueChanged.Invoke();
}
}
public event Action ValueChanged = () => { };
}
}