Last active
October 9, 2019 02:40
-
-
Save tsubaki/9427141 to your computer and use it in GitHub Desktop.
値の変更を通知するオブジェクト。基本型のみ可能っぽい。要4.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
[System.Serializable] | |
public class NotificationObject<T> | |
{ | |
public delegate void NotificationAction (T t); | |
private T data; | |
public NotificationObject (T t) | |
{ | |
Value = t; | |
} | |
public NotificationObject () | |
{ | |
} | |
~NotificationObject () | |
{ | |
Dispose (); | |
} | |
public UnityEngine.Events.UnityAction<T> action; | |
public T Value { | |
get { | |
return data; | |
} | |
set { | |
data = value; | |
Notice (); | |
} | |
} | |
private void Notice () | |
{ | |
if (action != null) | |
action (data); | |
} | |
public void Dispose () | |
{ | |
action = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下のように記述しておくと、値(Value)を変更した度にUpdateScoreLabelを呼び出す。
自身が破棄されるタイミングで下の処理で後片付けをしておくと吉。