You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
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<IntData, IntData> getAllTrappedCount; |
|
public static event Func<IntData, IntData> getTrappedRescuedCount; |
|
|
|
void Awake() |
|
{ |
|
trappedAll = transform.Find("TrappedAll").GetComponent<Text>(); |
|
trappedRescued = transform.Find("TrappedRescued").GetComponent<Text>(); |
|
trappedUnrescued = transform.Find("TrappedUnrescued").GetComponent<Text>(); |
|
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(); |
|
} |
|
}
|
|
|