Files
Studio/Assets/Panel_MQTTTestResult.cs
2025-05-25 14:19:35 +09:00

75 lines
2.5 KiB
C#

using Studio.Manage;
using Studio.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UVC.UI;
using XRLib;
using XRLib.UI;
namespace Studio
{
public class Panel_MQTTTestResult : PanelBase
{
public UVCKeyValueItem Item_Domain;
public UVCKeyValueItem Item_Port;
public ScrollRect scrollView_TopicResults;
public UI_MQTTTestResultItem prf_MQTTTestResultItem;
public Button button_Close;
public struct MQTTTestResult
{
public string topic;
public string message;
public string payload;
}
private void Awake()
{
button_Close = transform.DeepFind<Button>(nameof(button_Close));
button_Close.onClick.AddListener(Close);
scrollView_TopicResults = GetComponentInChildren<ScrollRect>();
Item_Port = transform.Find(nameof(Item_Port)).GetComponent< UVCKeyValueItem>();
Item_Domain = transform.Find(nameof(Item_Domain)).GetComponent< UVCKeyValueItem>();
prf_MQTTTestResultItem = Resources.Load<UI_MQTTTestResultItem>(ResourceURL.mqttTestResultItem);
}
private void Close()
{
Debug.Log("Close MQTT Test Result Panel.");
foreach (var item in items)
{
Destroy(item.gameObject);
}
items.Clear();
topics.Clear();
gameObject.SetActive(false);
}
public void Open(string domain, string port)
{
Debug.Log($"Open MQTT Test Result Panel. Domain: {domain}, Port: {port}");
Item_Domain.SetValue(domain);
Item_Port.SetValue(port);
gameObject.SetActive(true);
}
List<string> topics = new List<string>();
List<UI_MQTTTestResultItem> items = new List<UI_MQTTTestResultItem>();
public void AddResult(MQTTTestResult result)
{
Debug.Log($"Add MQTT Test Result. Topic: {result.topic}, Message: {result.message}, Payload Length: {result.payload.Length}");
if (topics.Contains(result.topic))
{
Debug.LogWarning($"Topic {result.topic} already exists in the results.");
return;
}
var item = Instantiate(prf_MQTTTestResultItem, scrollView_TopicResults.content);
item.SetResult(result.topic, result.message, result.payload);
item.transform.SetParent(scrollView_TopicResults.content);
items.Add(item);
}
}
}