修改请求接口
This commit is contained in:
parent
47a5d28d2f
commit
39870e7b64
File diff suppressed because it is too large
Load Diff
|
|
@ -69,7 +69,7 @@ public class Bootstrap : MonoSingleton<Bootstrap>
|
|||
private Dictionary<Transform, Tween> _fadeTweens = new Dictionary<Transform, Tween>();
|
||||
|
||||
|
||||
public Dictionary<string, string> urlDic = new Dictionary<string, string>();
|
||||
|
||||
[HideInInspector]
|
||||
public WebAdapter webAdapter;
|
||||
[HideInInspector]
|
||||
|
|
@ -83,28 +83,10 @@ public class Bootstrap : MonoSingleton<Bootstrap>
|
|||
[ContextMenu("1")]
|
||||
private void Awake()
|
||||
{
|
||||
var serverConfig = new System.Uri(Path.Combine(Application.streamingAssetsPath + @"/Config", "WebAddress.json"));
|
||||
GetText(serverConfig.ToString(), (temp) =>
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(temp))
|
||||
{
|
||||
Debug.Log("读取到的内容有:" + temp);
|
||||
urlDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(temp);
|
||||
//urlDic = JsonUtility.FromJson<Dictionary<string, string>>(temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("加载配置文件错误");
|
||||
}
|
||||
});
|
||||
|
||||
webAdapter = GetComponent<WebAdapter>();
|
||||
rayHitTester = GetComponent<RayHitTester>();
|
||||
}
|
||||
public void GetText(string url, Action<string> actionResult)
|
||||
{
|
||||
StartCoroutine(FileUtil.GetTextAsyn(url, actionResult));
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
//landMarks = new List<string> { "网络负荷:49.84 kw", "上网负荷:49.84 kw", "削峰负荷:49.84 kw", "填谷负荷:49.84 kw", "发电负荷:49.84 kw" };
|
||||
|
|
|
|||
|
|
@ -9,10 +9,17 @@ public class CityInfo : MonoBehaviour
|
|||
public ScreenTopStatistics sts = new ScreenTopStatistics();
|
||||
public AreaData areaData = new AreaData();
|
||||
public int Level = 0;
|
||||
private void Start()
|
||||
public GameObject tips;
|
||||
private void Awake()
|
||||
{
|
||||
if (!GetComponent<Collider>())
|
||||
gameObject.AddComponent<MeshCollider>();
|
||||
if (transform.childCount > 0)
|
||||
{
|
||||
tips = transform.GetChild(0).gameObject;
|
||||
tips.AddComponent<DistanceAdjuster>();
|
||||
tips.SetActive(false);
|
||||
}
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
|
|
@ -21,19 +28,15 @@ public class CityInfo : MonoBehaviour
|
|||
|
||||
}
|
||||
|
||||
public async void OnSetStationInfo()
|
||||
public void OnSetStationInfo()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(distCode) && distCode.Length == 6 && Level != 3)//获取市级市级下得区县
|
||||
if (!string.IsNullOrEmpty(distCode) && distCode.Length == 4 && 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
|
||||
{
|
||||
|
||||
DataController.Instance.loadingScreenTopStatisticsTasks.Add(DataController.Instance.GetProvincialLevelStationData(distCode));
|
||||
Debug.Log(1);
|
||||
}
|
||||
|
||||
SetScreenTopStatistices(0);
|
||||
if (!string.IsNullOrEmpty(distCode) && distCode.Length == 6 && transform.parent.gameObject.activeSelf && Level != 3)
|
||||
transform.parent.gameObject.SetActive(false);
|
||||
|
|
@ -41,14 +44,14 @@ public class CityInfo : MonoBehaviour
|
|||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public async void GetAreaData()
|
||||
public void GetAreaData()
|
||||
{
|
||||
if (Level != 3)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(distCode))
|
||||
{
|
||||
DataController.Instance.loadingAreaDataTasks.Add(DataController.Instance.GetAreaDataByDistCode(distCode));
|
||||
areaData = await DataController.Instance.GetAreaDataByDistCode(distCode);
|
||||
//areaData = await DataController.Instance.GetAreaDataByDistCode(distCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,19 +72,15 @@ public class CityInfo : MonoBehaviour
|
|||
|
||||
public void SetAreaData(AreaData a)
|
||||
{
|
||||
if (Level == 3)
|
||||
{
|
||||
areaData = a;
|
||||
}
|
||||
|
||||
areaData = a;
|
||||
|
||||
}
|
||||
|
||||
public void SetStationData(ScreenTopStatistics s)
|
||||
{
|
||||
if (Level == 3)
|
||||
{
|
||||
sts = s;
|
||||
SetScreenTopStatistices(0);
|
||||
}
|
||||
sts = s;
|
||||
SetScreenTopStatistices(0);
|
||||
}
|
||||
/// <summary>
|
||||
/// 0-代理用户,1-微电网,2-储能电站,3-光伏电站,4-风电站,5-充电站,6-楼宇空调
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ using UnityEngine;
|
|||
|
||||
public class DistanceAdjuster : MonoBehaviour
|
||||
{
|
||||
public float minDistance = 10;
|
||||
public float maxDistance = 120;
|
||||
private float minDistance = 10;
|
||||
private float maxDistance = 120;
|
||||
private float minScale = 0.3f;
|
||||
public float maxScale = 1;
|
||||
private Camera _camera;
|
||||
|
|
|
|||
|
|
@ -1,44 +1,96 @@
|
|||
using Adam;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class DataController : MonoSingleton<DataController>
|
||||
{
|
||||
public Dictionary<string, string> urlDic = new Dictionary<string, string>();
|
||||
public string distCode;
|
||||
private AreaStationData areaStationData = new AreaStationData();
|
||||
public AreaStationData areaStationData = new AreaStationData();
|
||||
private CityInfo[] cityInfos;
|
||||
|
||||
[HideInInspector]
|
||||
public List<UniTask<AreaData>> loadingAreaDataTasks = new List<UniTask<AreaData>>();
|
||||
[HideInInspector]
|
||||
public List<UniTask<ScreenTopStatistics>> loadingScreenTopStatisticsTasks = new List<UniTask<ScreenTopStatistics>>();
|
||||
public List<UniTask<AreaStationData>> loadingScreenTopStatisticsTasks = new List<UniTask<AreaStationData>>();
|
||||
|
||||
|
||||
private AreaData[] areaDatas;
|
||||
private ScreenTopStatistics[] screenTopStatistics;
|
||||
private AreaData[] areaDatasTasksReturnValue;
|
||||
/// <summary>
|
||||
/// 所有市级里面的区县信息
|
||||
/// </summary>
|
||||
private AreaStationData[] areaStationDatasTasksReturnValue;
|
||||
|
||||
private async void Start()
|
||||
public List<ScreenTopStatistics> screenTopStatisticss = new List<ScreenTopStatistics>();
|
||||
private void Awake()
|
||||
{
|
||||
var serverConfig = new System.Uri(Path.Combine(Application.streamingAssetsPath + @"/Config", "WebAddress.json"));
|
||||
GetText(serverConfig.ToString(), (temp) =>
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(temp))
|
||||
{
|
||||
urlDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("加载配置文件错误");
|
||||
}
|
||||
});
|
||||
}
|
||||
public void GetText(string url, Action<string> actionResult)
|
||||
{
|
||||
StartCoroutine(FileUtil.GetTextAsyn(url, actionResult));
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
Bootstrap.Instance.webAdapter.onStation.AddListener(SwitchStation);
|
||||
Bootstrap.Instance.webAdapter.onStartRequest.AddListener(OnInit);
|
||||
}
|
||||
|
||||
public void OnTEstBtn()
|
||||
{
|
||||
OnInit();
|
||||
}
|
||||
private async void OnInit()
|
||||
{
|
||||
await UniTask.Delay(1);
|
||||
areaStationData = await GetProvincialLevelStationData("37");
|
||||
cityInfos = transform.GetComponentsInChildren<CityInfo>();
|
||||
for (int i = 0; i < cityInfos.Length; i++)
|
||||
{
|
||||
//cityInfos[i].gameObject.SetActive(false);
|
||||
cityInfos[i].Init();
|
||||
}
|
||||
areaDatas = await UniTask.WhenAll(loadingAreaDataTasks);
|
||||
areaDatasTasksReturnValue = await UniTask.WhenAll(loadingAreaDataTasks);
|
||||
for (int i = 0; i < cityInfos.Length; i++)
|
||||
{
|
||||
string distCodeTemp = cityInfos[i].distCode;
|
||||
cityInfos[i].SetAreaData(GetAreaDateByDistCode(distCodeTemp));
|
||||
}
|
||||
screenTopStatistics = await UniTask.WhenAll(loadingScreenTopStatisticsTasks);
|
||||
areaStationDatasTasksReturnValue = await UniTask.WhenAll(loadingScreenTopStatisticsTasks);
|
||||
|
||||
for (int i = 0; i < areaStationDatasTasksReturnValue.Length; i++)
|
||||
{
|
||||
List<DataItem> tempDI = areaStationDatasTasksReturnValue[i].data;
|
||||
if (tempDI != null && tempDI.Count > 0)
|
||||
{
|
||||
for (int j = 0; j < tempDI.Count; j++)
|
||||
{
|
||||
screenTopStatisticss.Add(tempDI[j].screenTopStatistics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < cityInfos.Length; i++)
|
||||
{
|
||||
string distCodeTemp = cityInfos[i].distCode;
|
||||
cityInfos[i].SetStationData(GetAreLevelStationDataByDistCode(distCodeTemp));
|
||||
if (distCodeTemp.Length == 6)
|
||||
cityInfos[i].SetStationData(GetAreLevelStationDataByDistCode(distCodeTemp));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,10 +116,8 @@ public class DataController : MonoSingleton<DataController>
|
|||
/// <returns></returns>
|
||||
public async UniTask<ScreenTopStatistics> GetProvincialLevelStationInfo(string _distCode, string _disName)
|
||||
{
|
||||
if (_distCode.Length == 6)
|
||||
distCode = _distCode.Substring(0, 4);
|
||||
string url = Bootstrap.Instance.urlDic["地图信息汇总"];
|
||||
AreaStationData areaStationData = await AsyncWebReq.Get<AreaStationData>(url + distCode, Bootstrap.Instance.webAdapter.head, Bootstrap.Instance.webAdapter.token);
|
||||
string url = urlDic["地图信息汇总"];
|
||||
AreaStationData areaStationData = await AsyncWebReq.Get<AreaStationData>(url + _distCode, Bootstrap.Instance.webAdapter.head, Bootstrap.Instance.webAdapter.token);
|
||||
DataItem sts = areaStationData.data.Find(s => s.disName == _disName);
|
||||
if (sts == null)
|
||||
return null;
|
||||
|
|
@ -80,11 +130,11 @@ public class DataController : MonoSingleton<DataController>
|
|||
/// <returns></returns>
|
||||
public ScreenTopStatistics GetAreLevelStationDataByDistCode(string _distCode)
|
||||
{
|
||||
for (int i = 0; i < screenTopStatistics.Length; i++)
|
||||
for (int i = 0; i < screenTopStatisticss.Count; i++)
|
||||
{
|
||||
if (screenTopStatistics[i] != null && screenTopStatistics[i].distCode == _distCode)
|
||||
if (screenTopStatisticss[i] != null && screenTopStatisticss[i].distCode == _distCode)
|
||||
{
|
||||
return screenTopStatistics[i];
|
||||
return screenTopStatisticss[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -116,7 +166,7 @@ public class DataController : MonoSingleton<DataController>
|
|||
public async UniTask<AreaData> GetAreaDataByDistCode(string _distCode)
|
||||
{
|
||||
await UniTask.Delay(2);
|
||||
string url = Bootstrap.Instance.urlDic["地图弹出框"];
|
||||
string url = urlDic["地图弹出框"];
|
||||
AreaData areaData = await AsyncWebReq.Get<AreaData>($"{url}{_distCode}", Bootstrap.Instance.webAdapter.head, Bootstrap.Instance.webAdapter.token);
|
||||
if (!bool.Parse(areaData.success)) return null;
|
||||
return areaData;
|
||||
|
|
@ -124,11 +174,11 @@ public class DataController : MonoSingleton<DataController>
|
|||
|
||||
public AreaData GetAreaDateByDistCode(string _distCode)
|
||||
{
|
||||
for (int i = 0; i < areaDatas.Length; i++)
|
||||
for (int i = 0; i < areaDatasTasksReturnValue.Length; i++)
|
||||
{
|
||||
if (areaDatas[i].data.distCode == _distCode)
|
||||
if (areaDatasTasksReturnValue[i].data.distCode == _distCode)
|
||||
{
|
||||
return areaDatas[i];
|
||||
return areaDatasTasksReturnValue[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -139,9 +189,9 @@ public class DataController : MonoSingleton<DataController>
|
|||
/// </summary>
|
||||
/// <param name="_distCode"></param>
|
||||
/// <returns></returns>
|
||||
private async UniTask<AreaStationData> GetProvincialLevelStationData(string _distCode)
|
||||
public async UniTask<AreaStationData> GetProvincialLevelStationData(string _distCode)
|
||||
{
|
||||
string url = Bootstrap.Instance.urlDic["地图信息汇总"];
|
||||
string url = urlDic["地图信息汇总"];
|
||||
AreaStationData areaStationData = await AsyncWebReq.Get<AreaStationData>(url + _distCode, Bootstrap.Instance.webAdapter.head, Bootstrap.Instance.webAdapter.token);
|
||||
return areaStationData;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public class WebAdapter : MonoBehaviour
|
|||
}
|
||||
#endif
|
||||
public UnityEvent<int> onStation;
|
||||
public UnityEvent onStartRequest;
|
||||
public void OnLevelChange(int _level)
|
||||
{
|
||||
LevelChange(_level);
|
||||
|
|
@ -37,6 +38,7 @@ public class WebAdapter : MonoBehaviour
|
|||
string[] data = _headAndToken.Split("+");
|
||||
head = data[0];
|
||||
token = data[1];
|
||||
onStartRequest?.Invoke();
|
||||
Debug.Log("UnityLog==head==" + head);
|
||||
Debug.Log("UnityLog==token==" + token);
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 826 B After Width: | Height: | Size: 828 B |
Loading…
Reference in New Issue