Fixed problem with display module text input field

This commit is contained in:
Christen
2026-03-10 17:02:07 -04:00
parent 5119422966
commit a8679c35a9
3 changed files with 44 additions and 60 deletions

View File

@@ -4,7 +4,7 @@ using UnityEngine;
public class DistanceSensorModule : ModuleBase
{
// Keep a fixed-size array (no GC alloc every frame)
public string[] infoLines = new string[2];
public string[] infoLines = new string[1];
public override string moduleType => "Distance";
public override string moduleName => "Distance Sensor Module";
@@ -15,28 +15,26 @@ public class DistanceSensorModule : ModuleBase
void Update()
{
// Always show something immediately
infoLines[0] = $"ModuleID raw: '{moduleID}'";
// Poll at a fixed rate (avoids frame spam)
if (Time.unscaledTime < nextPollTime) return;
nextPollTime = Time.unscaledTime + (1f / Mathf.Max(1f, pollHz));
if (!int.TryParse(moduleID, out var id))
{
infoLines[1] = "ERROR: moduleID is not an int";
infoLines[0] = "ERROR: moduleID is not an int";
return;
}
try
{
double distance = ControlLibrary.get_distance_control(id);
infoLines[1] = $"Distance: {distance:F0} mm";
infoLines[0] = $"Distance: {distance:F0} mm";
}
catch (Exception e)
{
infoLines[1] = $"EXCEPTION: {e.GetType().Name}: {e.Message}";
Debug.LogException(e);
// infoLines[1] = $"EXCEPTION: {e.GetType().Name}: {e.Message}";
// Debug.LogException(e);
infoLines[0] = "Error: Could not detect any distance";
}
}