190 lines
6.9 KiB
C#
190 lines
6.9 KiB
C#
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
|
|
using Studio;
|
|
using Studio.Setting.Connect;
|
|
using Studio.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using XRLib.UI;
|
|
using Newtonsoft.Json;
|
|
using Best.HTTP.JSON;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
|
|
namespace XED.UI
|
|
{
|
|
public class Panel_Repository : PanelBase
|
|
{
|
|
UI_BaseDataButton apiDataButtonPrefab;
|
|
UI_MQTTDataButton mqttDataButtonPrefab;
|
|
|
|
UI_DataRepositoryButtonList APIDataList;
|
|
RectTransform Info_API;
|
|
RectTransform Info_Basedata;
|
|
RectTransform Info_MQTT;
|
|
RectTransform Info_MQTTdata;
|
|
|
|
TextMeshProUGUI TotalRequestPacketSize;
|
|
TextMeshProUGUI AverageRequestPacketSize;
|
|
TextMeshProUGUI TotalResponsePacketSize;
|
|
TextMeshProUGUI AverageResponsePacketSize;
|
|
TextMeshProUGUI MaximumResponseTime;
|
|
TextMeshProUGUI AverageResponseTime;
|
|
TextMeshProUGUI MaximumRequestPacketAPI;
|
|
TextMeshProUGUI MaximumResponsePacketAPI;
|
|
TextMeshProUGUI MaximumResponseTimeAPI;
|
|
|
|
TextMeshProUGUI RawData;
|
|
RectTransform rawDataRect;
|
|
float rawDataFoldHeight;
|
|
float rawDataOriginHeight;
|
|
RectTransform RawDataFoldButton;
|
|
bool isRawDataFoldOn;
|
|
TextMeshProUGUI PacketSize;
|
|
TextMeshProUGUI LastRequestTime;
|
|
TextMeshProUGUI LastResponseTime;
|
|
TextMeshProUGUI ElapsedTime;
|
|
|
|
LayoutGroup[] layoutGroups;
|
|
|
|
Dictionary<string, UI_BaseDataButton> apiButtons = new();
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
UI_ProtocolLabel[] protocolLabels = GetComponentsInChildren<UI_ProtocolLabel>();
|
|
foreach (UI_ProtocolLabel label in protocolLabels)
|
|
{
|
|
label.panel_Repository = this;
|
|
}
|
|
|
|
StudioService.Instance.onAPIDataLoaded += CreateAPIDataButton;
|
|
|
|
apiDataButtonPrefab = Resources.Load<UI_BaseDataButton>("Prefabs/UI/Button/UI_BaseDataButton");
|
|
mqttDataButtonPrefab = Resources.Load<UI_MQTTDataButton>("Prefabs/UI/Button/UI_MQTTDataButton");
|
|
|
|
layoutGroups = GetComponentsInChildren<LayoutGroup>();
|
|
rawDataRect = RawData.GetComponent<RectTransform>();
|
|
rawDataFoldHeight = rawDataRect.sizeDelta.y;
|
|
RawDataFoldButton.GetComponent<Button>().onClick.AddListener(OnClickRawDataFoldButton);
|
|
}
|
|
|
|
void CreateAPIDataButton(string name, StudioEntityWithState<object> value)
|
|
{
|
|
if (!apiButtons.ContainsKey(name))
|
|
{
|
|
// 버튼 새로 생성
|
|
var button = Instantiate(apiDataButtonPrefab, APIDataList.transform);
|
|
apiButtons.Add(name, button);
|
|
button.panel_Repository = this;
|
|
button.SetButtonData(name, value);
|
|
|
|
RebuildLayout();
|
|
}
|
|
else
|
|
{
|
|
// 버튼 데이터 업데이트
|
|
apiButtons[name].SetButtonData(name, value);
|
|
}
|
|
}
|
|
|
|
void CreateMQTTDataButton()
|
|
{
|
|
|
|
}
|
|
|
|
public void RebuildLayout()
|
|
{
|
|
foreach (var layout in layoutGroups)
|
|
{
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(layout.GetComponent<RectTransform>());
|
|
}
|
|
}
|
|
|
|
public void ShowInformation_API()
|
|
{
|
|
APITotalBoardEntity info = StudioService.Instance.GetAPIStatusBoarder();
|
|
|
|
TotalRequestPacketSize.text = info.TotalRequestPacketSize.ToString();
|
|
AverageRequestPacketSize.text = info.AverageRequestPacketSize.ToString();
|
|
TotalResponsePacketSize.text = info.TotalResponsePacketSize.ToString();
|
|
AverageResponsePacketSize.text = info.AverageResponsePacketSize.ToString();
|
|
MaximumResponseTime.text = info.MaximumResponseTime.ToString();
|
|
AverageResponseTime.text = info.AverageResponseTime.ToString();
|
|
MaximumRequestPacketAPI.text = info.MaximumRequestPacketAPI;
|
|
MaximumResponsePacketAPI.text = info.MaximumResponsePacketAPI;
|
|
MaximumResponseTimeAPI.text = info.MaximumResponseTimeAPI;
|
|
|
|
Info_API.gameObject.SetActive(true);
|
|
Info_Basedata.gameObject.SetActive(false);
|
|
Info_MQTT.gameObject.SetActive(false);
|
|
Info_MQTTdata.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ShowInformation_APIData(StudioEntityWithState<object> baseDataValue)
|
|
{
|
|
RawData.text = JsonConvert.SerializeObject(baseDataValue.Entity, Formatting.Indented);
|
|
|
|
rawDataOriginHeight = RawData.preferredHeight;
|
|
rawDataOriginHeight = Mathf.Max(rawDataFoldHeight, rawDataOriginHeight);
|
|
|
|
rawDataRect = RawData.GetComponent<RectTransform>();
|
|
Vector2 sizeDelta = rawDataRect.sizeDelta;
|
|
sizeDelta.y = rawDataOriginHeight;
|
|
rawDataRect.sizeDelta = sizeDelta;
|
|
|
|
var byteSize = System.Text.Encoding.Default.GetBytes(baseDataValue.Entity.ToString()).Length;
|
|
PacketSize.text = byteSize.ToString();
|
|
LastRequestTime.text = baseDataValue.lastRequestTime.ToString();
|
|
LastResponseTime.text = baseDataValue.lastResponseTime.ToString();
|
|
|
|
var elapsed = baseDataValue.elapsedTime;
|
|
int minutes = elapsed.Minutes;
|
|
int seconds = elapsed.Seconds;
|
|
int milliseconds = elapsed.Milliseconds;
|
|
ElapsedTime.text = $"{minutes:D2}:{seconds:D2}.{milliseconds:D3}";
|
|
|
|
Info_API.gameObject.SetActive(false);
|
|
Info_Basedata.gameObject.SetActive(true);
|
|
Info_MQTT.gameObject.SetActive(false);
|
|
Info_MQTTdata.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ShowInformation_MQTT()
|
|
{
|
|
|
|
Info_API.gameObject.SetActive(false);
|
|
Info_Basedata.gameObject.SetActive(false);
|
|
Info_MQTT.gameObject.SetActive(true);
|
|
Info_MQTTdata.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ShowInformation_MQTTData()
|
|
{
|
|
|
|
Info_API.gameObject.SetActive(false);
|
|
Info_Basedata.gameObject.SetActive(false);
|
|
Info_MQTT.gameObject.SetActive(false);
|
|
Info_MQTTdata.gameObject.SetActive(true);
|
|
}
|
|
|
|
void OnClickRawDataFoldButton()
|
|
{
|
|
if (isRawDataFoldOn)
|
|
{
|
|
Vector2 sizeDelta = rawDataRect.sizeDelta;
|
|
sizeDelta.y = rawDataOriginHeight;
|
|
rawDataRect.sizeDelta = sizeDelta;
|
|
RawDataFoldButton.localRotation = Quaternion.Euler(0, 0, 0);
|
|
isRawDataFoldOn = false;
|
|
}
|
|
else
|
|
{
|
|
Vector2 sizeDelta = rawDataRect.sizeDelta;
|
|
sizeDelta.y = rawDataFoldHeight;
|
|
rawDataRect.sizeDelta = sizeDelta;
|
|
RawDataFoldButton.localRotation = Quaternion.Euler(0f, 0f, 180f);
|
|
isRawDataFoldOn = true;
|
|
}
|
|
}
|
|
}
|
|
}
|