using Newtonsoft.Json; using Simulator.Config; using Simulator.Data; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UVC.Data; using UVC.Factory; namespace Simulator { public class WebReceiver : MonoBehaviour { public event Action onWebParameterRecived; public event Action onCameraReceived; static bool isFirstLoad = true; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { Debug.Log(isFirstLoad); if(isFirstLoad) { onWebParameterRecived += ComponentsManager.Instance.Request; onCameraReceived += FactoryCameraController.Instance.SetCamera; #if UNITY_EDITOR SimulationConfig.projectId = 470; SimulationConfig.logicId = 481; onWebParameterRecived?.Invoke(SimulationConfig.projectId.ToString()); DataRepository.Instance.MqttReceiver.SetDomainPort(Constants.MQTT_DOMAIN, Constants.MQTT_PORT); #else Application.ExternalCall("loadingComplete"); Debug.Log("call"); #endif isFirstLoad = false; } else { ComponentsManager.Instance.Request(SimulationConfig.projectId.ToString()); } } private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { SimulationConfig.projectId = 529; SceneManager.LoadScene(0); } } public void ReceiveWebParameterJson(string json) { var config = JsonConvert.DeserializeObject(json); SimulationConfig.logicId = int.Parse(config.logicId); SimulationConfig.projectId = int.Parse(config.projectId); onWebParameterRecived?.Invoke(SimulationConfig.projectId.ToString()); Debug.Log($"webparam:{json}"); } public void ReceiveWebConfigJson(string json) { var config = JsonConvert.DeserializeObject(json); Constants.HTTP_DOMAIN = $"{config.host}:{config.port}"; Constants.ACESS_TOKEN = config.accessToken; Debug.Log($"webconfig:{json}"); } public void ReceiveMQTTConfigJson(string json) { var config = JsonConvert.DeserializeObject(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}"); } } }