Files
Studio/Assets/TMPFolder/Panel_DataRepository.cs

214 lines
7.4 KiB
C#
Raw Normal View History

2025-05-22 18:29:09 +09:00
using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
2025-05-22 16:12:56 +09:00
using Studio;
using Studio.Setting.Connect;
using Studio.UI;
using TMPro;
using UnityEngine;
using XRLib.UI;
2025-05-22 18:29:09 +09:00
using Newtonsoft.Json;
using Best.HTTP.JSON;
using UnityEngine.UI;
2025-05-23 12:33:04 +09:00
using System.Collections.Generic;
2025-05-23 13:59:45 +09:00
using System;
2025-05-22 16:12:56 +09:00
2025-05-23 19:00:09 +09:00
namespace Studio
2025-05-22 16:12:56 +09:00
{
2025-05-23 19:00:09 +09:00
public class Panel_DataRepository : PanelBase
2025-05-22 16:12:56 +09:00
{
2025-05-23 12:33:04 +09:00
UI_BaseDataButton apiDataButtonPrefab;
UI_MQTTDataButton mqttDataButtonPrefab;
2025-05-22 16:12:56 +09:00
2025-05-23 19:00:09 +09:00
Button CloseButton;
2025-05-23 13:59:45 +09:00
RectTransform APIDataList;
RectTransform MQTTDataList;
RectTransform Panel_APIInfo;
RectTransform Panel_APIDataInfo;
RectTransform Panel_MQTTInfo;
RectTransform Panel_MQTTDataInfo;
2025-05-22 16:12:56 +09:00
TextMeshProUGUI TotalRequestPacketSize;
TextMeshProUGUI AverageRequestPacketSize;
TextMeshProUGUI TotalResponsePacketSize;
TextMeshProUGUI AverageResponsePacketSize;
TextMeshProUGUI MaximumResponseTime;
TextMeshProUGUI AverageResponseTime;
TextMeshProUGUI MaximumRequestPacketAPI;
TextMeshProUGUI MaximumResponsePacketAPI;
TextMeshProUGUI MaximumResponseTimeAPI;
2025-05-23 12:33:04 +09:00
LayoutGroup[] layoutGroups;
Dictionary<string, UI_BaseDataButton> apiButtons = new();
2025-05-23 13:59:45 +09:00
Dictionary<string, UI_MQTTDataButton> mqttButtons = new();
2025-05-23 12:33:04 +09:00
2025-05-23 19:00:09 +09:00
public bool apiConnected;
public bool mqttConnected;
2025-05-22 16:12:56 +09:00
public override void AfterAwake()
{
UI_ProtocolLabel[] protocolLabels = GetComponentsInChildren<UI_ProtocolLabel>();
foreach (UI_ProtocolLabel label in protocolLabels)
{
label.panel_Repository = this;
}
2025-05-23 12:33:04 +09:00
apiDataButtonPrefab = Resources.Load<UI_BaseDataButton>("Prefabs/UI/Button/UI_BaseDataButton");
mqttDataButtonPrefab = Resources.Load<UI_MQTTDataButton>("Prefabs/UI/Button/UI_MQTTDataButton");
2025-05-22 18:29:09 +09:00
2025-05-23 19:00:09 +09:00
CloseButton.onClick.AddListener(Deactivate);
2025-05-23 12:33:04 +09:00
layoutGroups = GetComponentsInChildren<LayoutGroup>();
2025-05-22 16:12:56 +09:00
}
2025-05-23 19:00:09 +09:00
private void OnEnable()
{
gameObject.transform.SetAsLastSibling();
/*
StudioService studioService = StudioService.Instance;
studioService.onAPIDataLoaded += UpdateAPIDataButton;
studioService.onMQTTDataLoaded += UpdateMQTTDataButton;
foreach (string key in studioService.apiData.Keys)
{
UpdateAPIDataButton(key, studioService.apiData[key]);
}
foreach (string key in studioService.mqttData.Keys)
{
UpdateMQTTDataButton(key, studioService.mqttData[key].Item1, studioService.mqttData[key].Item2);
}
*/
if (apiConnected)
{
2025-05-23 20:12:44 +09:00
StudioService studioService = StudioService.Instance;
2025-05-23 19:00:09 +09:00
studioService.onAPIDataLoaded += UpdateAPIDataButton;
foreach (string key in studioService.apiData.Keys)
{
UpdateAPIDataButton(key, studioService.apiData[key]);
}
}
if (mqttConnected)
{
2025-05-23 20:12:44 +09:00
StudioService studioService = StudioService.Instance;
2025-05-23 19:00:09 +09:00
studioService.onMQTTDataLoaded += UpdateMQTTDataButton;
foreach (string key in studioService.mqttData.Keys)
{
UpdateMQTTDataButton(key, studioService.mqttData[key].Item1, studioService.mqttData[key].Item2);
}
}
}
private void OnDisable()
{
//StudioService.Instance.onAPIDataLoaded -= UpdateAPIDataButton;
//StudioService.Instance.onMQTTDataLoaded -= UpdateMQTTDataButton;
}
2025-05-23 13:59:45 +09:00
void UpdateAPIDataButton(string name, StudioEntityWithState<object> value)
2025-05-22 16:12:56 +09:00
{
2025-05-23 12:33:04 +09:00
if (!apiButtons.ContainsKey(name))
{
// <20><>ư <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
var button = Instantiate(apiDataButtonPrefab, APIDataList.transform);
apiButtons.Add(name, button);
button.panel_Repository = this;
button.SetButtonData(name, value);
2025-05-22 18:29:09 +09:00
2025-05-23 12:33:04 +09:00
RebuildLayout();
}
else
{
// <20><>ư <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ
apiButtons[name].SetButtonData(name, value);
}
2025-05-22 16:12:56 +09:00
}
2025-05-23 13:59:45 +09:00
void UpdateMQTTDataButton(string name, Dictionary<string, Dictionary<string, string>> value, TimeSpan elapsedTime)
2025-05-23 12:33:04 +09:00
{
2025-05-23 13:59:45 +09:00
if (!mqttButtons.ContainsKey(name))
{
var button = Instantiate(mqttDataButtonPrefab, MQTTDataList.transform);
mqttButtons.Add(name, button);
button.panel_Repository = this;
button.SetButtonData(name, value, elapsedTime);
2025-05-22 16:12:56 +09:00
2025-05-23 13:59:45 +09:00
RebuildLayout();
}
else
{
mqttButtons[name].SetButtonData(name, value, elapsedTime);
}
2025-05-23 12:33:04 +09:00
}
public void RebuildLayout()
2025-05-22 18:29:09 +09:00
{
2025-05-23 12:33:04 +09:00
foreach (var layout in layoutGroups)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(layout.GetComponent<RectTransform>());
}
2025-05-22 18:29:09 +09:00
}
2025-05-22 16:12:56 +09:00
public void ShowInformation_API()
{
2025-05-23 20:12:44 +09:00
APITotalBoardEntity info = StudioService.Instance.GetAPIStatusBoarder();
2025-05-22 16:12:56 +09:00
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;
2025-05-23 13:59:45 +09:00
Panel_APIInfo.gameObject.SetActive(true);
Panel_APIDataInfo.gameObject.SetActive(false);
Panel_MQTTInfo.gameObject.SetActive(false);
Panel_MQTTDataInfo.gameObject.SetActive(false);
2025-05-22 16:12:56 +09:00
}
2025-05-23 12:33:04 +09:00
public void ShowInformation_APIData(StudioEntityWithState<object> baseDataValue)
2025-05-22 16:12:56 +09:00
{
2025-05-23 13:59:45 +09:00
Panel_APIDataInfo.GetComponent<Panel_APIDataInfo>().ShowData(baseDataValue);
Panel_APIInfo.gameObject.SetActive(false);
Panel_APIDataInfo.gameObject.SetActive(true);
Panel_MQTTInfo.gameObject.SetActive(false);
Panel_MQTTDataInfo.gameObject.SetActive(false);
2025-05-23 12:33:04 +09:00
}
public void ShowInformation_MQTT()
{
2025-05-23 13:59:45 +09:00
Panel_APIInfo.gameObject.SetActive(false);
Panel_APIDataInfo.gameObject.SetActive(false);
Panel_MQTTInfo.gameObject.SetActive(true);
Panel_MQTTDataInfo.gameObject.SetActive(false);
2025-05-23 12:33:04 +09:00
}
2025-05-23 13:59:45 +09:00
public void ShowInformation_MQTTData(Dictionary<string, Dictionary<string, string>> data, TimeSpan elapsedTime)
2025-05-23 12:33:04 +09:00
{
2025-05-23 13:59:45 +09:00
Panel_MQTTDataInfo.GetComponent<Panel_MQTTDataInfo>().ShowData(data, elapsedTime);
2025-05-23 12:33:04 +09:00
2025-05-23 13:59:45 +09:00
Panel_APIInfo.gameObject.SetActive(false);
Panel_APIDataInfo.gameObject.SetActive(false);
Panel_MQTTInfo.gameObject.SetActive(false);
Panel_MQTTDataInfo.gameObject.SetActive(true);
2025-05-22 18:29:09 +09:00
}
2025-05-23 19:00:09 +09:00
void Deactivate()
{
gameObject.SetActive(false);
}
2025-05-22 16:12:56 +09:00
}
}