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

49 行
1.1 KiB

using System;
using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView
{
public abstract class DataWatchContainer : VisualContainer
{
protected DataWatchContainer()
{
// trigger data source reset when entering leaving panel
onEnter += AddWatch;
onLeave += RemoveWatch;
}
// called when Serialized object has changed
// only works while widget is in a panel
public virtual void OnDataChanged()
{ }
protected abstract object toWatch { get; }
protected void AddWatch()
{
var watch = toWatch as UnityEngine.Object;
if (watch != null && panel != null)
// TODO: consider a disposable handle?
DataWatchService.AddDataSpy(this, watch, OnDataChanged);
}
protected void RemoveWatch()
{
var watch = toWatch as UnityEngine.Object;
try
{
if (watch != null && panel != null)
DataWatchService.RemoveDataSpy(watch, OnDataChanged);
}
catch (Exception e)
{
Debug.LogException(e);
if (watch != null)
{
Debug.LogWarningFormat("No datawatch is registered to: {0} it is type {1}", watch.name, watch.GetType());
}
}
}
}
}