mirror of
https://github.com/BotChain-Robots/ui.git
synced 2026-07-08 15:07:22 +02:00
Fixed problem with display module text input field
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user