using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; public class InfoWindow : WindowBase { private Dictionary _AearInfoDict = new Dictionary(); [Header("当前激活面板")] public GameObject CurrentActivePanel=null; [Header("AearInfo")] public Transform AearInfoParent; public Animator AearInfoAnimator; public Button AearInfoActiveBtn; public Text emptytipTxt; public GameObject miniMap; public override void Init() { base.Init(); AearInfoActiveBtn.onClick.AddListener(SetAearInfoPanelActive); } #region 区域数据相关 public void AddAearInfo(string aearID, AearInfoType infoType) { if (!_AearInfoDict.ContainsKey(aearID)) { //添加 GameObject go = GameObject.Instantiate(Resources.Load("Prefab/UI/AearInfo"), AearInfoParent); AearInfo aearInfo = go.GetComponent(); if (aearInfo != null) { aearInfo._aearID = aearID; _AearInfoDict.Add(aearID, aearInfo); } else { Debug.LogError(aearID + "不存在AearInfo"); } //设定数据 switch (infoType) { case AearInfoType.摄像: aearInfo.SetCameraBtn(); break; case AearInfoType.湿度和可见度: aearInfo.shidu = Random.Range(20, 30); aearInfo.kejiandu = Random.Range(500, 600); break; case AearInfoType.PM2_5: aearInfo.pm2_5 = Random.Range(50, 70); break; case AearInfoType.噪音: aearInfo.zaoyin = Random.Range(50, 80); break; } //初始化Info脚本 aearInfo.Init(); } else { AearInfo aearInfo; if (_AearInfoDict.TryGetValue(aearID, out aearInfo)) { //设定数据 switch (infoType) { case AearInfoType.摄像: aearInfo.SetCameraBtn(); break; case AearInfoType.湿度和可见度: aearInfo.shidu = Random.Range(20, 30); aearInfo.kejiandu = Random.Range(500, 600); break; case AearInfoType.PM2_5: aearInfo.pm2_5 = Random.Range(50, 70); break; case AearInfoType.噪音: aearInfo.zaoyin = Random.Range(50, 80); break; } } } //更新排序 UpdateAearInfo(); if (emptytipTxt.gameObject.activeSelf) { emptytipTxt.gameObject.SetActive(false); } } public void UpdateAearInfo() { //先排号字典 AearDictSort(); //数据的数组 AearInfo[] aearInfos = AearInfoParent.gameObject.GetComponentsInChildren(); int index = 0; foreach (var item in _AearInfoDict) { for (int i = 0; i < aearInfos.Length; i++) { if (aearInfos[i]._aearID == item.Key) { aearInfos[i].transform.SetSiblingIndex(index); index++; break; } } } } /// /// 区域字典排序 /// private void AearDictSort() { Dictionary dict = _AearInfoDict.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); _AearInfoDict = dict; } public void SetAearInfoPanelActive() { if (AearInfoActiveBtn.transform.localScale.x==1) { AearInfoAnimator.CrossFade("AearInfoShow", 0.1f); AearInfoActiveBtn.transform.localScale = new Vector3(-1, 1, 1); } else { AearInfoAnimator.CrossFade("AearInfoHide", 0.1f); AearInfoActiveBtn.transform.localScale = new Vector3(1, 1, 1); } } #endregion }