55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using UnityEngine;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Octopus.Simulator.Networks;
|
|
using UVC.Networks;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
|
|
namespace Octopus.Simulator
|
|
{
|
|
public class LogicDataManager : MonoBehaviour
|
|
{
|
|
public LogicData currentData;
|
|
public LogicWebConfig config;
|
|
|
|
public event Action<LogicData> onLogicUpdated;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
FindAnyObjectByType<WebReceiver>().onParameterRecived += RequestInfo;
|
|
FindAnyObjectByType<MQTTManager>().onLogicUpdated += RequestInfo;
|
|
}
|
|
|
|
public void RequestInfo()
|
|
{
|
|
WebManager.Instance.Request_Get($"{WebManager.Instance.apiConfig.logic}/{WebParameters.config.logicId}", (flag, value) =>
|
|
{
|
|
if (flag)
|
|
{
|
|
var info = JsonConvert.DeserializeObject<LogicInfo>(value);
|
|
onLogicUpdated?.Invoke(info.data);
|
|
GetDataFromInfo(info.data);
|
|
}
|
|
});
|
|
}
|
|
|
|
void GetDataFromInfo(LogicData Data)
|
|
{
|
|
currentData = Data;
|
|
config = Data.webConfig;
|
|
if (currentData.ModelFiles.Count >= 1)
|
|
{
|
|
SimulationModelFile files = currentData.ModelFiles[currentData.ModelFiles.Count - 1];
|
|
if (files.id.HasValue)
|
|
{
|
|
WebParameters.config.modelId = files.id.Value.ToString();
|
|
var saveload = FindAnyObjectByType<SaveLoadmanager>();
|
|
saveload.Onclick_Load(files.data.info);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |