using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TrappedInfo : MonoBehaviour { public Text trappedAll; public Text trappedRescued; public Text trappedUnrescued; public static event Func getAllTrappedCount; public static event Func getTrappedRescuedCount; void Awake() { trappedAll = transform.Find("TrappedAll").GetComponent(); trappedRescued = transform.Find("TrappedRescued").GetComponent(); trappedUnrescued = transform.Find("TrappedUnrescued").GetComponent(); MessageDispatcher.AddListener("SomeoneOutOfTrap", UpdateInfoListener); //开启窗口时,每当有人被营救,更新显示信息 } private void OnDestroy() { MessageDispatcher.RemoveListener("SomeoneOutOfTrap", UpdateInfoListener); //开启窗口时,每当有人被营救,更新显示信息 } void UpdateInfoListener(IMessage obj) { UpdateInfo(); } void UpdateInfo() { IntData dataAll = new IntData(0); if (getAllTrappedCount != null) { dataAll = getAllTrappedCount(dataAll); } trappedAll.text = dataAll.value.ToString(); IntData dataRescued = new IntData(0); if (getTrappedRescuedCount != null) { dataRescued = getTrappedRescuedCount(dataRescued); } trappedRescued.text = dataRescued.value.ToString(); trappedUnrescued.text = (dataAll.value - dataRescued.value).ToString(); } //窗口每次打开都更新显示信息 void OnEnable() { UpdateInfo(); } }