using System;
namespace LobbyRelaySample
{
///
/// Something that exposes some data that, when changed, an observer would want to be notified about automatically.
/// Used for UI elements and for keeping our local Lobby state synchronized with the remote Lobby service data.
/// (See http://gameprogrammingpatterns.com/observer.html to learn more.)
///
/// In your Observed child implementations, be sure to call OnChanged when setting the value of any property.
///
/// The type of object to be observed.
public abstract class Observed
{
///
/// If you want to copy all of the values, and only trigger OnChanged once.
///
///
public abstract void CopyObserved(T oldObserved);
public Action onChanged { get; set; }
public Action onDestroyed { get; set; }
///
/// Should be implemented into every public property of the observed
///
/// Instance of the observed that changed.
protected void OnChanged(T observed)
{
onChanged?.Invoke(observed);
}
protected void OnDestroyed(T observed)
{
onDestroyed?.Invoke(observed);
}
}
}