using AX.MessageSystem; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// 到场力量界面 /// public class ThePowerToPresentPanel : MonoBehaviour { //到场力量消防车信息父类 private Transform mArrivedCarParent; //到场力量消防车信息预设 private GameObject mArrivedCarPrefab; private List> MyCarList = new List>(); private Dictionary>> mMyFireTrucks = new Dictionary>>(); //按中队、车类型组织车辆数据(string:组织机构;List:某类型车有多少辆) //private Dictionary>> mOrgCars = // new Dictionary>>(); private Toggle mTgl; private void Awake() { MessageDispatcher.AddListener(FireInfoMessage.ArrivedForce.ToString(), ShowThePowerToPresentPanel); Init(); gameObject.SetActive(false); } private void OnEnable() { mMyFireTrucks = PowerPresentData.Instance.GetAllPresentCar(); DeleEnginesUI(); MyCarList.Clear(); foreach (var mFireTruck in mMyFireTrucks.Values) { MyCarList.AddRange(mFireTruck); } ShowArrivedTruckMessage(MyCarList); } private void OnDisable() { MessageDispatcher.AddListener(FireInfoMessage.ArrivedForce.ToString(), ShowThePowerToPresentPanel); } private void DeleEnginesUI() { foreach (Transform dept in mArrivedCarParent.transform) { Destroy(dept.gameObject); } } /// /// 打开,显示到场力量面板 /// /// private void ShowThePowerToPresentPanel(IMessage obj) { bool b = (bool)obj.Data; gameObject.SetActive(b); } void Init() { mTgl = transform.parent.transform.Find("TopPanel/Tool/FireInfo/FireSiteInfoPopup/Background/Item (4)/4").GetComponent(); mArrivedCarParent = transform.Find("Body/Scroll View/Viewport/Content"); mArrivedCarPrefab = Resources.Load("ArrivedCarMsg") as GameObject; } void ShowArrivedTruckMessage(List> CarList) { CarArrivedMsgShow(CarList); if (!gameObject.activeSelf) { gameObject.SetActive(true); } } void CarArrivedMsgShow(List> ShowCarList) { foreach (Transform t in mArrivedCarParent) { Destroy(t.gameObject); } if (ShowCarList.Count > 0) { foreach (KeyValuePair item in ShowCarList) { GameObject c = Instantiate(mArrivedCarPrefab, mArrivedCarParent); c.transform.Find("FireTruckNameAText").GetComponent().text = item.Key.TypeName; c.transform.Find("FireTruckNumAText").GetComponent().text = item.Value.ToString(); } } } /// /// 关闭面板 /// public void CloseThePowerToPresentPanel() { gameObject.SetActive(false); mTgl.isOn = false; } }