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.

132 lines
3.6 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InfoWnd : MonoBehaviour
{
public Text carInTxt;
public Text carOutTxt;
public Text carAllTxt;
public Text dateTxt;
public Button roadInfoCloseBtn;
//路况检测窗口
public GameObject roadInfoWnd;
public GameObject colorTitle;
public Transform roadInfoGroup;
public string date;
//路况信息字典
public Dictionary<string, RoadInfo> Road_Dict = new Dictionary<string, RoadInfo>();
public void Init()
{
if (roadInfoWnd.activeSelf)
{
SetRoadInfoActive(false);
}
roadInfoCloseBtn.onClick.AddListener(()=> { SetRoadInfoActive(false); });
InitRoadDict();
}
//初始化路况字典
private void InitRoadDict()
{
for (int i = 0; i < roadInfoGroup.childCount; i++)
{
RoadInfo info = new RoadInfo();
Text txt = roadInfoGroup.transform.GetChild(i).GetComponent<Text>();
info.roadName = roadInfoGroup.transform.GetChild(i).name;
info.flowRate = 100;
info.carFlow = 0;
info.Iswarning = false;
txt.text = string.Format(" ▶ "+"{0:G}"+" "+"{1:G}"+" "+ "{2:00.00}"+ "%"+" "+ "{3:G}", info.roadName,info.carFlow,info.flowRate,info.Iswarning?"是":"否");
Road_Dict.Add(info.roadName, info);
}
}
//更新路况信息方法
public void UpdateRoadDict(string roadName)
{
RoadInfo info = null;
if(Road_Dict.TryGetValue(roadName,out info))
{
Text txt= roadInfoGroup.Find(roadName).GetComponent<Text>();
txt.text = string.Format(" ▶ " + "{0:G}" + " " + "{1:G}" + " " + "{2:00.00}" + "%" + " " + "{3:G}", info.roadName, info.carFlow, info.flowRate, info.Iswarning ? "是" : "否");
}
}
//TODo
public RoadInfo GetRoadInfo(string roadName)
{
RoadInfo info = new RoadInfo();
if(Road_Dict.TryGetValue(roadName, out info))
{
return info;
}
return null;
}
public void SetCarInText(int Addvalue)
{
int n = int.Parse(carInTxt.text) + Addvalue;
carInTxt.text = n.ToString();
int n1 = int.Parse(carAllTxt.text) + Addvalue;
carAllTxt.text = n1.ToString();
}
public void SetCarOutText(int Addvalue)
{
int n = int.Parse(carOutTxt.text) + Addvalue;
carOutTxt.text = n.ToString();
int n1 = int.Parse(carAllTxt.text) + Addvalue;
carAllTxt.text = n1.ToString();
}
public void SetColorTitleActive()
{
if (colorTitle.activeSelf != false)
{
colorTitle.SetActive(false);
}
else
{
colorTitle.SetActive(true);
}
}
public void UpdateTime()
{
var hour = DateTime.Now.Hour;
var minute = DateTime.Now.Minute;
var second = DateTime.Now.Second;
var year = DateTime.Now.Year;
var month = DateTime.Now.Month;
var day = DateTime.Now.Day;
date = string.Format("{0:D4}/{1:D2}/{2:D2}" + "-" + "{3:D2}:{4:D2}:{5:D2} ", year, month, day, hour, minute, second);
dateTxt.text = date;
}
public void SetRoadInfoActive(bool t)
{
roadInfoWnd.SetActive(t);
}
}