Files
Simulation/Assets/WorkSpace/LH/LogicData/LogicDataManager.cs
2025-07-07 09:57:13 +09:00

73 lines
2.3 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 Awake()
{
FindAnyObjectByType<MQTTManager>().onLogicUpdated += UpdateInfo;
}
public void RequestInfo()
{
var requestURL = $"{WebManager.Instance.apiConfig.logic}/{WebParameters.config.logicId}";
WebManager.Instance.Reqeust<LogicData>(requestURL, RequestType.GET, GetDataFromInfo);
}
public void UpdateInfo()
{
var requestURL = $"{WebManager.Instance.apiConfig.logic}/{WebParameters.config.logicId}";
WebManager.Instance.Reqeust<LogicData>(requestURL, RequestType.GET, UpdateDataFromInfo);
}
void GetDataFromInfo(LogicData Data)
{
onLogicUpdated?.Invoke(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);
}
}
}
void UpdateDataFromInfo(LogicData Data)
{
onLogicUpdated?.Invoke(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();
}
}
}
}
}