84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
using Newtonsoft.Json;
|
|
using Simulator.Config;
|
|
using Simulator.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UVC.Data;
|
|
using UVC.Factory;
|
|
|
|
namespace Simulator
|
|
{
|
|
public class WebReceiver : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 웹 프론트에서 파라미터 수신 완료 시 발행 (SimulationConfig에 값 세팅 후)
|
|
/// </summary>
|
|
public event Action onWebParameterReceived;
|
|
public event Action<string> onCameraReceived;
|
|
private static bool isFirstLoad = true;
|
|
private FactoryCameraController _cameraController;
|
|
|
|
void Start()
|
|
{
|
|
Debug.Log(isFirstLoad);
|
|
if(isFirstLoad)
|
|
{
|
|
_cameraController = FactoryCameraController.Instance;
|
|
onCameraReceived += _cameraController.SetCamera;
|
|
#if UNITY_EDITOR
|
|
SimulationConfig.projectId = 470;
|
|
SimulationConfig.logicId = 481;
|
|
DataRepository.Instance.MqttReceiver.SetDomainPort(Constants.MQTT_DOMAIN, Constants.MQTT_PORT);
|
|
onWebParameterReceived?.Invoke();
|
|
#else
|
|
Application.ExternalCall("loadingComplete");
|
|
Debug.Log("call");
|
|
#endif
|
|
isFirstLoad = false;
|
|
}
|
|
else
|
|
{
|
|
onWebParameterReceived?.Invoke();
|
|
}
|
|
}
|
|
|
|
public void ReceiveWebParameterJson(string json)
|
|
{
|
|
var config = JsonConvert.DeserializeObject<SimulatorConfig>(json);
|
|
SimulationConfig.logicId = int.Parse(config.logicId);
|
|
SimulationConfig.projectId = int.Parse(config.projectId);
|
|
onWebParameterReceived?.Invoke();
|
|
Debug.Log($"webparam:{json}");
|
|
}
|
|
|
|
public void ReceiveWebConfigJson(string json)
|
|
{
|
|
var config = JsonConvert.DeserializeObject<SimulatorWebConfig>(json);
|
|
Constants.HTTP_DOMAIN = $"{config.host}:{config.port}";
|
|
Constants.ACCESS_TOKEN = config.accessToken;
|
|
Debug.Log($"webconfig:{json}");
|
|
}
|
|
|
|
public void ReceiveMQTTConfigJson(string json)
|
|
{
|
|
var config = JsonConvert.DeserializeObject<SimulatorMQTTConfig>(json);
|
|
Constants.MQTT_DOMAIN = config.host;
|
|
Constants.MQTT_PORT = int.Parse(config.port);
|
|
DataRepository.Instance.MqttReceiver.SetDomainPort(Constants.MQTT_DOMAIN, Constants.MQTT_PORT);
|
|
Debug.Log($"mqttparam:{json}");
|
|
}
|
|
|
|
public void camAngle(string json)
|
|
{
|
|
onCameraReceived?.Invoke(json);
|
|
Debug.Log($"webCam:{json}");
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_cameraController != null)
|
|
onCameraReceived -= _cameraController.SetCamera;
|
|
}
|
|
}
|
|
} |