您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

37 行
1.3 KiB

using System;
namespace LobbyRelaySample
{
/// <summary>
/// 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.
///
/// In your Observed child implementations, be sure to call OnChanged when setting the value of any property.
/// </summary>
/// <typeparam name="T">The type of object to be observed.</typeparam>
public abstract class Observed<T>
{
/// <summary>
/// If you want to copy all of the values, and only trigger OnChanged once.
/// </summary>
/// <param name="oldObserved"></param>
public abstract void CopyObserved(T oldObserved);
public Action<T> onChanged { get; set; }
public Action<T> onDestroyed { get; set; }
/// <summary>
/// Should be implemented into every public property of the observed
/// </summary>
/// <param name="observed">Instance of the observed that changed.</param>
protected void OnChanged(T observed)
{
onChanged?.Invoke(observed);
}
protected void OnDestroy(T observed)
{
onDestroyed?.Invoke(observed);
}
}
}