using AX.MessageSystem; using AX.Network.Protocols; using AX.NetworkSystem; using AX.Serialization; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TrappedTime : MonoBehaviour { public Text hour; public Text minute; public static string time; private static bool end = false; private static string endTime; private static IntData data = new IntData(0); // Use this for initialization void Awake () { if (hour == null) { hour = transform.Find("TrappedHour").GetComponent(); } if (minute == null) { minute = transform.Find("TrappedMinute").GetComponent(); } NetworkMessageDispatcher.AddListener("TIME_SYNC",updateTime); //MessageDispatcher.AddListener("SomeoneOutOfTrap", StopTime); //每当有人被营救时,就发送一条该指令 } private void updateTime(BinaryMessage obj) { if (!end) { time = obj.Body.Deserialize(); } else { time = endTime; } DateTime dateTime = Convert.ToDateTime(time); hour.text = dateTime.Hour.ToString(); minute.text = dateTime.Minute.ToString(); } public static Func getAllWoundedTrappedCount; //获取目前仍然被困的人员 /*private void StopTime(IMessage obj) { IntData data = new IntData(0); if(getAllTrappedCount != null) { data = getAllTrappedCount(data); } if(data.value <= 0) { //如果没有人被困了,就停止计时 NetworkMessageDispatcher.RemoveListener("TIME_SYNC", updateTime); } } */ public static void CheckStopTime() { data.Clear(); if (!end) { if (getAllWoundedTrappedCount != null) { data = getAllWoundedTrappedCount(data); } if (data.value <= 0) { //如果没有人被困了,就停止计时 //NetworkMessageDispatcher.RemoveListener("TIME_SYNC", updateTime); end = true; endTime = TIME_SYNC.time; } } } private void OnDestroy() { NetworkMessageDispatcher.RemoveListener("TIME_SYNC", updateTime); } }