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.
109 lines
4.0 KiB
109 lines
4.0 KiB
3 years ago
|
using AX.MessageSystem;
|
||
|
using MobileCFFSInfo;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 现场信息窗口
|
||
|
/// </summary>
|
||
|
public class CarInfo : MonoBehaviour {
|
||
|
|
||
|
public string introHead = "共收到<color=red>";
|
||
|
public string introEnd = "</color>辆车。";
|
||
|
public int carNum;//车辆辆数
|
||
|
public Text IntroText;
|
||
|
|
||
|
private GameObject WithinContent;//可控范围内车辆UI容器
|
||
|
private GameObject OutsideContent;//超出可控范围车辆UI容器
|
||
|
|
||
|
private Button CloseButton;
|
||
|
|
||
|
public GameObject ItemPrefab;//车辆条目预设
|
||
|
public float r = 1000;//可控范围
|
||
|
|
||
|
// Use this for initialization
|
||
|
void Start () {
|
||
|
|
||
|
IntroText = transform.Find("Intro").GetComponent<Text>();
|
||
|
|
||
|
WithinContent = transform.Find("Within/Detail/Scroll View/Viewport/Content").gameObject;
|
||
|
OutsideContent = transform.Find("Outside/Detail/Scroll View/Viewport/Content").gameObject;
|
||
|
|
||
|
CloseButton = transform.Find("CloseButton").GetComponent<Button>();
|
||
|
CloseButton.onClick.AddListener(CloseCarInfoWin);
|
||
|
|
||
|
//先注册上弹出现场信息窗口的事件,再设置默认隐藏
|
||
|
MessageDispatcher.AddListener("POPUP_CARINFO_WIN", Popup);
|
||
|
gameObject.SetActive(false);
|
||
|
}
|
||
|
|
||
|
private void CloseCarInfoWin()
|
||
|
{
|
||
|
//隐藏现场信息窗口
|
||
|
gameObject.SetActive(false);
|
||
|
}
|
||
|
|
||
|
private void Popup(IMessage obj)
|
||
|
{
|
||
|
if (obj.Data == null)
|
||
|
{//通过现场信息按钮点击打开窗口没发数据过来,为null
|
||
|
gameObject.SetActive(true);
|
||
|
}
|
||
|
else
|
||
|
{//接收到移动指挥终端通过服务器返回回来信息后自动打开会发送数据过来,不为null
|
||
|
var FFSInfo = (FFSInfo)obj.Data;
|
||
|
List<FireTruckInfo> truckInfos = FFSInfo.FireTruckInfos;
|
||
|
|
||
|
carNum = truckInfos.Count;
|
||
|
IntroText.text = introHead + carNum + introEnd;
|
||
|
|
||
|
foreach (Transform child in WithinContent.transform)
|
||
|
{
|
||
|
Destroy(child.gameObject);
|
||
|
}
|
||
|
foreach (Transform child in OutsideContent.transform)
|
||
|
{
|
||
|
Destroy(child.gameObject);
|
||
|
}
|
||
|
|
||
|
foreach (FireTruckInfo truckInfo in truckInfos)
|
||
|
{
|
||
|
if (MobileCFFSInfo.Vector2.Distance(truckInfo.Position,FFSInfo.Origin) <= r)
|
||
|
{//生成可控范围内车辆信息UI条目
|
||
|
GameObject item = Instantiate(ItemPrefab, WithinContent.transform) as GameObject;
|
||
|
item.transform.Find("FireSquadron").GetComponent<Text>().text = truckInfo.FireSquadron;
|
||
|
item.transform.Find("CarType").GetComponent<Text>().text = truckInfo.Type3D;
|
||
|
item.transform.Find("PlateNumber").GetComponent<Text>().text = truckInfo.PlateNumber;
|
||
|
item.transform.Find("Mission").GetComponent<Text>().text = truckInfo.Mission;
|
||
|
}
|
||
|
|
||
|
if (MobileCFFSInfo.Vector2.Distance(truckInfo.Position, FFSInfo.Origin) > r)
|
||
|
{//生成超出可控范围车辆信息UI条目
|
||
|
GameObject item = Instantiate(ItemPrefab, OutsideContent.transform) as GameObject;
|
||
|
item.transform.Find("FireSquadron").GetComponent<Text>().text = truckInfo.FireSquadron;
|
||
|
item.transform.Find("CarType").GetComponent<Text>().text = truckInfo.Type3D;
|
||
|
item.transform.Find("PlateNumber").GetComponent<Text>().text = truckInfo.PlateNumber;
|
||
|
item.transform.Find("Mission").GetComponent<Text>().text = truckInfo.Mission;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
gameObject.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update () {
|
||
|
|
||
|
}
|
||
|
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
CloseButton.onClick.RemoveListener(CloseCarInfoWin);
|
||
|
|
||
|
MessageDispatcher.RemoveListener("POPUP_CARINFO_WIN", Popup);
|
||
|
}
|
||
|
}
|