网上演练贵港万达广场(人员密集)
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.

82 lines
2.4 KiB

4 years ago
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<Text>();
}
if (minute == null)
{
minute = transform.Find("TrappedMinute").GetComponent<Text>();
}
NetworkMessageDispatcher.AddListener("TIME_SYNC",updateTime);
//MessageDispatcher.AddListener("SomeoneOutOfTrap", StopTime); //每当有人被营救时,就发送一条该指令
}
private void updateTime(BinaryMessage obj)
{
if (!end)
{
time = obj.Body.Deserialize<string>();
}
else
{
time = endTime;
}
DateTime dateTime = Convert.ToDateTime(time);
hour.text = dateTime.Hour.ToString();
minute.text = dateTime.Minute.ToString();
}
public static Func<IntData, IntData> 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);
}
}