67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BestHTTP;
|
|
using Cysharp.Threading.Tasks;
|
|
using EasyInject.Attributes;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace GameLogic.Origin.data
|
|
{
|
|
[GameObjectBean]
|
|
public class AgvTaskListData : MonoBehaviour
|
|
{
|
|
[Autowired] private NetWorkComponent _netWork;
|
|
private List<AgvTaskInfo> _agvTaskList = new ();
|
|
[LabelText("ÈÎÎñÁбí"),ShowInInspector] public Dictionary<string, List<AgvTaskInfo>> AgvTaskMap = new Dictionary<string, List<AgvTaskInfo>>();
|
|
private UniTask _task;
|
|
private void Start()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
_task = UniTask.RunOnThreadPool(delegate
|
|
{
|
|
_netWork.RemoteGetAgvTaskListData((HTTPRequest originalRequest, HTTPResponse response) =>
|
|
{
|
|
try
|
|
{
|
|
if (response == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (response.IsSuccess)
|
|
{
|
|
JObject resultData = JObject.Parse(response.DataAsText);
|
|
string json = resultData["object"].ToString();
|
|
if (!string.IsNullOrEmpty(json))
|
|
{
|
|
List<AgvTaskInfo> agvTasks = JsonConvert.DeserializeObject<List<AgvTaskInfo>>(json);
|
|
_agvTaskList = agvTasks;
|
|
AgvTaskMap = _agvTaskList.GroupBy( i=> i.fromDevice).ToDictionary(s => s.Key, s => s.ToList());
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Console.WriteLine(e);
|
|
// throw;
|
|
}
|
|
finally
|
|
{
|
|
originalRequest.Send();
|
|
}
|
|
|
|
});
|
|
}, false);
|
|
}
|
|
|
|
|
|
}
|
|
} |