unity text 内容改变事件
示例代码如下 监测Text组件内容改变
[RequireComponent(typeof(Text))]
public class FollowText : MonoBehaviour {
public Text targetText;
private void Awake() {
BindAction();
}
private void BindAction()
{
if (targetText == null)
return;
targetText.UnregisterDirtyVerticesCallback(OnChanged);
targetText.RegisterDirtyVerticesCallback(OnChanged);
}
private void OnChanged()
{
transform.GetComponent<Text>().text = targetText.text;
}
}