From cdc7c8acce9447f3ccd5f42f0f2d782ede3935f6 Mon Sep 17 00:00:00 2001 From: uc-hoba Date: Wed, 10 Jun 2026 15:47:31 +0800 Subject: [PATCH] feat(GroundControl): add MQTT message handling and summary display --- Assets/Main.unity | 32 +++++++++++++++++--- Assets/Scripts/GroundControl.cs | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/Assets/Main.unity b/Assets/Main.unity index 742e300..0f66f6c 100644 --- a/Assets/Main.unity +++ b/Assets/Main.unity @@ -1088,9 +1088,17 @@ MonoBehaviour: Port 1883 Topic - "unity/#" + "station/#" - Is Connected false + Is Connected + false + + + + Ground Control + + Message + Summary "No messages" ' m_isRightToLeft: 0 @@ -1196,6 +1204,10 @@ MonoBehaviour: - brokerPort - topic - IsConnected + - target: {fileID: 848515247} + groupLabel: Ground Control + fields: + - MessageSummary --- !u!222 &587767521 CanvasRenderer: m_ObjectHideFlags: 0 @@ -1709,11 +1721,23 @@ MonoBehaviour: m_EditorClassIdentifier: Assembly-CSharp::UltraCombos.MqttBridge brokerHost: localhost brokerPort: 1883 - topic: unity/# + topic: station/# verbose: 1 onMessage: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 848515247} + m_TargetAssemblyTypeName: UltraCombos.GroundControl, Assembly-CSharp + m_MethodName: OnMQTT + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!4 &952249954 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GroundControl.cs b/Assets/Scripts/GroundControl.cs index aaeacaf..61ccca4 100644 --- a/Assets/Scripts/GroundControl.cs +++ b/Assets/Scripts/GroundControl.cs @@ -1,9 +1,38 @@ +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; using UnityEngine; namespace UltraCombos { public class GroundControl : MonoBehaviour { + [System.Serializable] + public class Component + { + [JsonProperty("key")] public string Key { get; set; } + [JsonProperty("order")] public int Order { get; set; } + [JsonProperty("width")] public float? Width { get; set; } + } + + [System.Serializable] + public class Message + { + [JsonProperty("id")] public string Id { get; set; } + [JsonProperty("step")] public int Step { get; set; } + [JsonProperty("stepName")] public string StepName { get; set; } + [JsonProperty("character")] public string Character { get; set; } + [JsonProperty("components")] public List Components { get; set; } = new(); + [JsonProperty("title")] public string Title { get; set; } + [JsonProperty("result")] public string Result { get; set; } + [JsonProperty("updatedAt")] public long UpdatedAt { get; set; } + } + + public Dictionary messages = new(); + public string Station1 => GetSummary(0); + public string Station2 => GetSummary(1); + public string Station3 => GetSummary(2); + private void Start() { @@ -13,6 +42,30 @@ namespace UltraCombos { } + + public void OnMQTT(string topic, string payload) + { + var parts = topic.Split("/"); + if (parts.Length != 3) + { + return; + } + var id = parts[1]; + var msg = JsonConvert.DeserializeObject(payload); + messages[id] = msg; + } + + private string GetSummary(int index) + { + var keys = messages.Keys.ToArray(); + if (keys.Length <= index) + { + return "No messages"; + } + var id = keys[index]; + var msg = messages[id]; + return $"{id} #{msg.Step} {msg.Character}"; + } } }