From e99159a3681cb50d8926b18a9c9233e1a7e67297 Mon Sep 17 00:00:00 2001 From: "tom.hempel" Date: Thu, 6 Nov 2025 13:18:12 +0100 Subject: [PATCH] Add notes handling to TaskButtonManager for UDP commands --- Unity/Assets/Scripts/ARVRMenu.cs | 45 +++++++++++++++++++++++----- Unity/Assets/Scripts/NotesDisplay.cs | 23 ++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 Unity/Assets/Scripts/NotesDisplay.cs diff --git a/Unity/Assets/Scripts/ARVRMenu.cs b/Unity/Assets/Scripts/ARVRMenu.cs index 931bdea..ca5abfb 100644 --- a/Unity/Assets/Scripts/ARVRMenu.cs +++ b/Unity/Assets/Scripts/ARVRMenu.cs @@ -18,12 +18,17 @@ public class TaskButtonManager : MonoBehaviour private string pendingTimerCommand = null; private readonly object sceneLock = new object(); private readonly object timerLock = new object(); + private readonly object notesLock = new object(); private TaskTimer taskTimer; + private NotesDisplay notesDisplay; + private string pendingNotesText = null; private void Start() { // Find TaskTimer in the scene taskTimer = FindObjectOfType(); + // Find NotesDisplay in the scene + notesDisplay = FindObjectOfType(); if (enableUDPControl) { @@ -60,6 +65,23 @@ public class TaskButtonManager : MonoBehaviour } } + // Check for pending notes updates (must be done on main thread) + lock (notesLock) + { + if (!string.IsNullOrEmpty(pendingNotesText)) + { + if (notesDisplay != null) + { + notesDisplay.SetNotes(pendingNotesText); + } + else + { + Debug.LogWarning("NotesDisplay not found in scene. Cannot display notes text."); + } + pendingNotesText = null; + } + } + // VR Tasks (Keys 1-4) if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)) LoadSceneByName("VR-Task1"); @@ -131,12 +153,12 @@ public class TaskButtonManager : MonoBehaviour if (string.IsNullOrEmpty(message)) return; - // Parse command format: COMMAND:Parameter - string[] parts = message.Split(':'); - if (parts.Length >= 2) + // Parse command format: COMMAND:Parameter (Parameter may contain additional colons) + int separatorIndex = message.IndexOf(':'); + if (separatorIndex > 0 && separatorIndex < message.Length - 1) { - string commandType = parts[0].Trim().ToUpper(); - string parameter = parts[1].Trim(); + string commandType = message.Substring(0, separatorIndex).Trim().ToUpper(); + string parameter = message.Substring(separatorIndex + 1); // keep raw to preserve spaces/colons if (commandType == "SWITCH") { @@ -156,14 +178,23 @@ public class TaskButtonManager : MonoBehaviour } Debug.Log($"Scheduled timer command: {parameter}"); } + else if (commandType == "NOTES") + { + // Notes display command + lock (notesLock) + { + pendingNotesText = parameter; + } + Debug.Log($"Scheduled notes update: {parameter}"); + } else { - Debug.LogWarning($"Unknown UDP command type: {commandType}. Expected: SWITCH or TIMER"); + Debug.LogWarning($"Unknown UDP command type: {commandType}. Expected: SWITCH, TIMER or NOTES"); } } else { - Debug.LogWarning($"Invalid UDP command format: {message}. Expected format: COMMAND:Parameter (e.g., SWITCH:SceneName or TIMER:START)"); + Debug.LogWarning($"Invalid UDP command format: {message}. Expected format: COMMAND:Parameter (e.g., SWITCH:SceneName, TIMER:START or NOTES:Your text)"); } } diff --git a/Unity/Assets/Scripts/NotesDisplay.cs b/Unity/Assets/Scripts/NotesDisplay.cs new file mode 100644 index 0000000..0482ce2 --- /dev/null +++ b/Unity/Assets/Scripts/NotesDisplay.cs @@ -0,0 +1,23 @@ +using UnityEngine; +using TMPro; + +public class NotesDisplay : MonoBehaviour +{ + [Header("Notes UI")] + [Tooltip("TextMeshProUGUI field where received notes will be displayed")] + public TextMeshProUGUI notesText; + + public void SetNotes(string text) + { + if (notesText != null) + { + notesText.text = text; + } + else + { + Debug.LogWarning("NotesDisplay: notesText is not assigned in the inspector."); + } + } +} + +