109 lines
3.1 KiB
C#
109 lines
3.1 KiB
C#
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace Octopus.Simulator.Networks
|
|
{
|
|
public class WebReceiver : MonoBehaviour
|
|
{
|
|
public SimulatorConfig config;
|
|
public event Action onParameterRecived;
|
|
public event Action<string> onMqttConfigReceived;
|
|
public event Action<string> onWebConfigReceived;
|
|
public event Action<string> onCameraReceived;
|
|
public event Action onCompleteWindowReceived;
|
|
public event Action<string> onLLMModelsReceived;
|
|
public event Action<string> onLLMModelsUpdated;
|
|
|
|
|
|
public void Start()
|
|
{
|
|
WebParameters.code = "";
|
|
onParameterRecived += FindAnyObjectByType<ProjectDataManager>().RequestInfo;
|
|
onParameterRecived += FindAnyObjectByType<LogicDataManager>().RequestInfo;
|
|
#if UNITY_EDITOR
|
|
config.projectId = "78";
|
|
//config.simulationId = "15";
|
|
config.logicId = "83";
|
|
WebParameters.config = config;
|
|
onParameterRecived?.Invoke();
|
|
#else
|
|
Application.ExternalCall("loadingComplete");
|
|
#endif
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(Input.GetKeyDown(KeyCode.G)){
|
|
var text=Resources.Load<TextAsset>("simulation_model_infos_list");
|
|
ReceiveLLMModels(text.text);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.F))
|
|
{
|
|
var text = Resources.Load<TextAsset>("simulation_model_infos_list_add");
|
|
ReceiveLLMUpdate(text.text);
|
|
}
|
|
}
|
|
|
|
public void ReceiveWebParameterJson(string json)
|
|
{
|
|
config = JsonConvert.DeserializeObject<SimulatorConfig>(json);
|
|
WebParameters.config = config;
|
|
onParameterRecived?.Invoke();
|
|
Debug.Log($"webparam:{json}");
|
|
}
|
|
|
|
public void ReceiveMQTTConfigJson(string json)
|
|
{
|
|
onMqttConfigReceived?.Invoke(json);
|
|
Debug.Log($"mqttconfig:{json}");
|
|
}
|
|
|
|
public void ReceiveWebConfigJson(string json)
|
|
{
|
|
onWebConfigReceived?.Invoke(json);
|
|
Debug.Log($"webconfig:{json}");
|
|
}
|
|
|
|
public void camAngle(string json)
|
|
{
|
|
onCameraReceived?.Invoke(json);
|
|
Debug.Log($"webCam:{json}");
|
|
}
|
|
|
|
public void ReceiveLLMModels(string json)
|
|
{
|
|
var data = JsonConvert.DeserializeObject<LLMWraper>(json);
|
|
onLLMModelsReceived?.Invoke(data.info);
|
|
}
|
|
|
|
public void ReceiveLLMUpdate(string json)
|
|
{
|
|
var data = JsonConvert.DeserializeObject<LLMWraper>(json);
|
|
onLLMModelsUpdated?.Invoke(data.info);
|
|
}
|
|
|
|
public void ReceiveCompleteWindow()
|
|
{
|
|
onCompleteWindowReceived?.Invoke();
|
|
Debug.Log("CompleteReceive");
|
|
}
|
|
|
|
public void SetKeyBoardOn()
|
|
{
|
|
WebGLInput.captureAllKeyboardInput = true;
|
|
}
|
|
|
|
public void SetKeyBoardOff()
|
|
{
|
|
WebGLInput.captureAllKeyboardInput = false;
|
|
}
|
|
}
|
|
|
|
public class LLMWraper
|
|
{
|
|
public string info;
|
|
}
|
|
} |