using System.Collections; using System.Collections.Generic; using UnityEngine; public class CityInfo : MonoBehaviour { public string distCode; public string cityName; public ScreenTopStatistics sts = new ScreenTopStatistics(); public AreaData areaData = new AreaData(); public int Level = 0; private void Start() { if (!GetComponent()) gameObject.AddComponent(); } public void Init() { OnSetStationInfo(); GetAreaData(); } public async void OnSetStationInfo() { if (!string.IsNullOrEmpty(distCode) && distCode.Length == 6 && Level != 3) { DataController.Instance.loadingScreenTopStatisticsTasks.Add(DataController.Instance.GetProvincialLevelStationInfo(distCode, cityName)); sts = await DataController.Instance.GetProvincialLevelStationInfo(distCode, cityName); } else if (!string.IsNullOrEmpty(distCode) && distCode.Length == 4 && Level != 3) sts = DataController.Instance.GetProvincialLevelStationDataByDistCode(distCode); else { } SetScreenTopStatistices(sts); if (!string.IsNullOrEmpty(distCode) && distCode.Length == 6 && transform.parent.gameObject.activeSelf && Level != 3) transform.parent.gameObject.SetActive(false); if (Level == 3) gameObject.SetActive(false); } public async void GetAreaData() { if (Level != 3) { if (!string.IsNullOrEmpty(distCode)) { DataController.Instance.loadingAreaDataTasks.Add(DataController.Instance.GetAreaDataByDistCode(distCode)); areaData = await DataController.Instance.GetAreaDataByDistCode(distCode); } } } public void SetScreenTopStatistices(ScreenTopStatistics sts) { if (sts != null) { transform.GetChild(0).GetComponent().SetInfo(sts.agentCons); transform.GetChild(1).GetComponent().SetInfo(sts.energyStation); transform.GetChild(2).GetComponent().SetInfo(sts.phoStation); transform.GetChild(3).GetComponent().SetInfo(sts.microGrid); transform.GetChild(4).GetComponent().SetInfo(sts.airCondition); transform.GetChild(5).GetComponent().SetInfo(sts.windStation); } else { for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(false); } } } public void SetAreaData(AreaData a) { if (Level == 3) { areaData = a; } } public void SetStationData(ScreenTopStatistics s) { if (Level == 3) { sts = s; SetScreenTopStatistices(s); } } }