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

45 lines
1.3 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GetRealtimeConsume : MonoBehaviour {
/// <summary>
/// 出水方实时消耗总量(data)= 各个出水方流量(Flow)之和 - 消火栓分担的流量(消火栓上的TotalFlow)
/// </summary>
private FloatData data = new FloatData(0);
/// <summary>
/// 统计实时消耗的事件
/// </summary>
public static event Func<FloatData, FloatData> getAllRealtimeConsume;
private void OnEnable()
{
data.Clear();
if(getAllRealtimeConsume != null)
{
data = getAllRealtimeConsume(data);
}
GetComponent<Text>().text = Math.Round(data.value,2) + "L/s";
StartCoroutine(GetRealtimeOnInternal());
}
private void OnDisable()
{
StopCoroutine(GetRealtimeOnInternal());
}
IEnumerator GetRealtimeOnInternal()
{
while (true)
{
yield return new WaitForSeconds(1.0f);
data.Clear();
if (getAllRealtimeConsume != null)
{
data = getAllRealtimeConsume(data);
}
GetComponent<Text>().text = Math.Round(data.value, 2) + "L/s";
}
}
}