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

70 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class PowerMessage : MonoBehaviour
{
public GameObject CarMsgPrefab;
public Transform CarMsgParent;
public Text NowDis;
public Text NowTime;
private List<KeyValuePair<FireCarEngine, int>> MyCarList = new List<KeyValuePair<FireCarEngine, int>>();
private float showTime = 5f;
void Start()
{
}
//用来显示车辆信息的方法
public void ShowMessage(List<KeyValuePair<FireCarEngine, int>> CarList, string Distance, string time)
{
showTime = 5f;
if (MyCarList != CarList)
{
MyCarList = CarList;
CarMsgShow(CarList);
}
NowDis.text = Distance;
NowTime.text = time;
if (!gameObject.activeSelf)
gameObject.SetActive(true);
}
public void CarMsgShow(List<KeyValuePair<FireCarEngine, int>> ShowCarList)
{
foreach (Transform t in CarMsgParent)
{
Destroy(t.gameObject);
}
if (ShowCarList.Count > 0)
{
//var GroupResult = from FireCarEngine in ShowCarList group FireCarEngine by FireCarEngine.TypeName;
//foreach (IGrouping<string, FireCarEngine> item in GroupResult)
//{
// GameObject c = Instantiate(CarMsgPrefab, CarMsgParent);
// c.transform.Find("CarName").GetComponent<Text>().text = item.Key;
// c.transform.Find("CarNum").GetComponent<Text>().text = item.Count().ToString();
//}
foreach (KeyValuePair<FireCarEngine, int> item in ShowCarList)
{
GameObject c = Instantiate(CarMsgPrefab, CarMsgParent);
c.transform.Find("CarName").GetComponent<Text>().text = item.Key.TypeName;
c.transform.Find("CarNum").GetComponent<Text>().text = item.Value.ToString();
}
}
}
void Update()
{
if (gameObject.activeSelf)
{
showTime -= Time.deltaTime;
if (showTime <= 0)
{
gameObject.SetActive(false);
showTime = 5f;
}
}
}
}