Fixed weird underline on UI text and made text bigger

Made-with: Cursor
This commit is contained in:
Leo Qu
2026-03-08 21:39:00 -04:00
parent 3d3285003f
commit 44fb8276ff
17 changed files with 1064 additions and 3956 deletions

View File

@@ -1,12 +1,11 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro;
public class AngleControllerSlider : MonoBehaviour public class AngleControllerSlider : MonoBehaviour
{ {
public GameObject angleUI; public GameObject angleUI;
public Slider angleSlider; public Slider angleSlider;
public TextMeshProUGUI angleLabel; public Text angleLabel;
private Transform currentCap; private Transform currentCap;

View File

@@ -1,12 +1,11 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro;
public class BlockJointController : MonoBehaviour public class BlockJointController : MonoBehaviour
{ {
public Transform rotatingCap; public Transform rotatingCap;
public Slider angleSlider; public Slider angleSlider;
public TextMeshProUGUI angleLabel; public Text angleLabel;
private float currentAngle = 0f; private float currentAngle = 0f;

View File

@@ -1,12 +1,11 @@
using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class ControlPanel : MonoBehaviour public class ControlPanel : MonoBehaviour
{ {
[Header("Core UI (assign in Inspector)")] [Header("Core UI (assign in Inspector)")]
public TMP_InputField inputField; public InputField inputField;
public TMP_Dropdown directionDropdown; public Dropdown directionDropdown;
public Button button; // existing Send/Rotate button in hierarchy public Button button; // existing Send/Rotate button in hierarchy
private enum Mode { None, DC, Display, Speaker } private enum Mode { None, DC, Display, Speaker }
@@ -20,17 +19,15 @@ public class ControlPanel : MonoBehaviour
private int _savedDirectionIndex = 0; private int _savedDirectionIndex = 0;
private string _savedDisplayInput = ""; private string _savedDisplayInput = "";
// Found automatically (no hierarchy edits) private Text _caption; // child "DegreesCaption"
private TextMeshProUGUI _caption; // child "DegreesCaption" private Text _buttonText; // child "RotateButton/Text (TMP)"
private TextMeshProUGUI _buttonText; // child "RotateButton/Text (TMP)"
private GameObject _directionCaptionGO; private GameObject _directionCaptionGO;
private GameObject _directionDropdownGO; private GameObject _directionDropdownGO;
// Created in code (Speaker mode only)
private Button _uploadButton; private Button _uploadButton;
private TextMeshProUGUI _uploadButtonText; private Text _uploadButtonText;
private Button _playButton; private Button _playButton;
private TextMeshProUGUI _playButtonText; private Text _playButtonText;
private void Awake() private void Awake()
{ {
@@ -91,10 +88,10 @@ public class ControlPanel : MonoBehaviour
private void CacheUIFromHierarchy() private void CacheUIFromHierarchy()
{ {
var captionT = transform.Find("DegreesCaption"); var captionT = transform.Find("DegreesCaption");
if (captionT != null) _caption = captionT.GetComponent<TextMeshProUGUI>(); if (captionT != null) _caption = captionT.GetComponent<Text>();
var buttonTextT = transform.Find("RotateButton/Text (TMP)"); var buttonTextT = transform.Find("RotateButton/Text (TMP)");
if (buttonTextT != null) _buttonText = buttonTextT.GetComponent<TextMeshProUGUI>(); if (buttonTextT != null) _buttonText = buttonTextT.GetComponent<Text>();
var dirCaptionT = transform.Find("DirectionCaption"); var dirCaptionT = transform.Find("DirectionCaption");
if (dirCaptionT != null) _directionCaptionGO = dirCaptionT.gameObject; if (dirCaptionT != null) _directionCaptionGO = dirCaptionT.gameObject;
@@ -253,20 +250,17 @@ public class ControlPanel : MonoBehaviour
} }
} }
private void CopyTMPStyle(TextMeshProUGUI source, TextMeshProUGUI target) private void CopyTextStyle(Text source, Text target)
{ {
if (source == null || target == null) return; if (source == null || target == null) return;
target.font = source.font; target.font = source.font;
target.fontSharedMaterial = source.fontSharedMaterial;
target.fontStyle = source.fontStyle; target.fontStyle = source.fontStyle;
target.fontSize = source.fontSize; target.fontSize = source.fontSize;
target.enableAutoSizing = source.enableAutoSizing;
target.color = source.color; target.color = source.color;
target.enableVertexGradient = source.enableVertexGradient;
target.alignment = source.alignment; target.alignment = source.alignment;
target.enableWordWrapping = source.enableWordWrapping; target.horizontalOverflow = source.horizontalOverflow;
target.richText = source.richText; target.verticalOverflow = source.verticalOverflow;
} }
// ------------------------- // -------------------------
@@ -289,14 +283,13 @@ public class ControlPanel : MonoBehaviour
// Copy Send button look // Copy Send button look
CopyButtonStyle(button, _uploadButton); CopyButtonStyle(button, _uploadButton);
var textGo = new GameObject("Text (TMP)"); var textGo = new GameObject("Text");
textGo.transform.SetParent(go.transform, false); textGo.transform.SetParent(go.transform, false);
_uploadButtonText = textGo.AddComponent<TextMeshProUGUI>(); _uploadButtonText = textGo.AddComponent<Text>();
_uploadButtonText.text = "Upload Audio"; _uploadButtonText.text = "Upload Audio";
// Copy Send text look CopyTextStyle(_buttonText, _uploadButtonText);
CopyTMPStyle(_buttonText, _uploadButtonText); _uploadButtonText.alignment = TextAnchor.MiddleCenter;
_uploadButtonText.alignment = TextAlignmentOptions.Center;
// Layout: above Play // Layout: above Play
var rt = go.GetComponent<RectTransform>(); var rt = go.GetComponent<RectTransform>();
@@ -353,14 +346,13 @@ public class ControlPanel : MonoBehaviour
// Copy Send button look // Copy Send button look
CopyButtonStyle(button, _playButton); CopyButtonStyle(button, _playButton);
var textGo = new GameObject("Text (TMP)"); var textGo = new GameObject("Text");
textGo.transform.SetParent(go.transform, false); textGo.transform.SetParent(go.transform, false);
_playButtonText = textGo.AddComponent<TextMeshProUGUI>(); _playButtonText = textGo.AddComponent<Text>();
_playButtonText.text = "Play Audio"; _playButtonText.text = "Play Audio";
// Copy Send text look CopyTextStyle(_buttonText, _playButtonText);
CopyTMPStyle(_buttonText, _playButtonText); _playButtonText.alignment = TextAnchor.MiddleCenter;
_playButtonText.alignment = TextAlignmentOptions.Center;
// Layout: between Upload and Send // Layout: between Upload and Send
var rt = go.GetComponent<RectTransform>(); var rt = go.GetComponent<RectTransform>();

View File

@@ -1,6 +1,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;

View File

@@ -30,17 +30,12 @@ public class DistanceSensorModule : ModuleBase
try try
{ {
// Control library call
double distance = ControlLibrary.get_distance_control(id); double distance = ControlLibrary.get_distance_control(id);
infoLines[1] = $"Distance: {distance:F0} mm"; infoLines[1] = $"Distance: {distance:F0} mm";
} }
catch (Exception e) catch (Exception e)
{ {
// SHOW THE PROBLEM ON SCREEN (works in release builds)
infoLines[1] = $"EXCEPTION: {e.GetType().Name}: {e.Message}"; infoLines[1] = $"EXCEPTION: {e.GetType().Name}: {e.Message}";
// Also log to Player.log (works in builds)
Debug.LogException(e); Debug.LogException(e);
} }
} }

View File

@@ -1,7 +1,7 @@
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro;
public class PositionControlGizmo : MonoBehaviour public class PositionControlGizmo : MonoBehaviour
{ {
[Header("Gizmo Settings")] [Header("Gizmo Settings")]

View File

@@ -1,13 +1,12 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro;
/// <summary> /// <summary>
/// IK-mode side panel: shows fixed-module hint. Text is set in the scene. /// IK-mode side panel: shows fixed-module hint. Text is set in the scene.
/// </summary> /// </summary>
public class IKModulePanel : MonoBehaviour public class IKModulePanel : MonoBehaviour
{ {
public TextMeshProUGUI moduleInfoText; public Text moduleInfoText;
[Header("Panel Layout")] [Header("Panel Layout")]
public float panelWidth = 260f; public float panelWidth = 260f;

View File

@@ -1,17 +1,17 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using TMPro;
public class LiveViewModulePanel : MonoBehaviour public class LiveViewModulePanel : MonoBehaviour
{ {
[Header("Module Info")] [Header("Module Info")]
public TextMeshProUGUI moduleInfoText; public Text moduleInfoText;
[Header("Servo Control")] [Header("Servo Control")]
public GameObject servoControlSection; public GameObject servoControlSection;
public Slider servoAngleSlider; public Slider servoAngleSlider;
public TextMeshProUGUI servoAngleLabel; public Text servoAngleLabel;
[Header("DC + Display Control (Reused)")] [Header("DC + Display Control (Reused)")]
public GameObject moduleControlSection; public GameObject moduleControlSection;
@@ -24,7 +24,7 @@ public class LiveViewModulePanel : MonoBehaviour
private bool _sliderDragging; private bool _sliderDragging;
private ControlPanel panel; private ControlPanel panel;
private GameObject sensorTextContainer; private GameObject sensorTextContainer;
private readonly System.Collections.Generic.List<TextMeshProUGUI> sensorTextLines = new System.Collections.Generic.List<TextMeshProUGUI>(); private readonly System.Collections.Generic.List<Text> sensorTextLines = new System.Collections.Generic.List<Text>();
void Start() void Start()
{ {
@@ -170,10 +170,9 @@ public class LiveViewModulePanel : MonoBehaviour
sensorTextContainer = new GameObject("SensorTextContainer"); sensorTextContainer = new GameObject("SensorTextContainer");
sensorTextContainer.transform.SetParent(parent, false); sensorTextContainer.transform.SetParent(parent, false);
var src = moduleInfoText.rectTransform; var src = moduleInfoText.GetComponent<RectTransform>();
var rt = sensorTextContainer.AddComponent<RectTransform>(); var rt = sensorTextContainer.AddComponent<RectTransform>();
// Place under the moduleInfoText
rt.anchorMin = src.anchorMin; rt.anchorMin = src.anchorMin;
rt.anchorMax = src.anchorMax; rt.anchorMax = src.anchorMax;
rt.pivot = src.pivot; rt.pivot = src.pivot;
@@ -198,24 +197,16 @@ public class LiveViewModulePanel : MonoBehaviour
var go = new GameObject($"SensorLine{sensorTextLines.Count}"); var go = new GameObject($"SensorLine{sensorTextLines.Count}");
go.transform.SetParent(sensorTextContainer.transform, false); go.transform.SetParent(sensorTextContainer.transform, false);
var tmp = go.AddComponent<TextMeshProUGUI>(); var txt = go.AddComponent<Text>();
txt.font = moduleInfoText.font;
txt.fontStyle = FontStyle.Bold;
txt.fontSize = 22;
txt.color = Color.white;
txt.alignment = TextAnchor.UpperLeft;
txt.horizontalOverflow = HorizontalWrapMode.Wrap;
txt.verticalOverflow = VerticalWrapMode.Overflow;
// Match your UI font + material var rt = go.GetComponent<RectTransform>();
tmp.font = moduleInfoText.font;
tmp.fontSharedMaterial = moduleInfoText.fontSharedMaterial;
// Your requested style (like screenshot)
tmp.fontStyle = FontStyles.Bold;
tmp.fontSize = 22f;
tmp.enableAutoSizing = false;
tmp.color = Color.white;
tmp.enableVertexGradient = false;
tmp.alignment = TextAlignmentOptions.TopLeft;
tmp.enableWordWrapping = true;
// Layout: stacked lines
var rt = tmp.rectTransform;
rt.anchorMin = new Vector2(0f, 1f); rt.anchorMin = new Vector2(0f, 1f);
rt.anchorMax = new Vector2(1f, 1f); rt.anchorMax = new Vector2(1f, 1f);
rt.pivot = new Vector2(0f, 1f); rt.pivot = new Vector2(0f, 1f);
@@ -225,10 +216,9 @@ public class LiveViewModulePanel : MonoBehaviour
rt.anchoredPosition = new Vector2(0f, y); rt.anchoredPosition = new Vector2(0f, y);
rt.sizeDelta = new Vector2(0f, lineH); rt.sizeDelta = new Vector2(0f, lineH);
sensorTextLines.Add(tmp); sensorTextLines.Add(txt);
} }
// Hide extras
for (int i = 0; i < sensorTextLines.Count; i++) for (int i = 0; i < sensorTextLines.Count; i++)
sensorTextLines[i].gameObject.SetActive(i < count); sensorTextLines[i].gameObject.SetActive(i < count);
} }

View File

@@ -24,7 +24,7 @@ public class TopologyBuilder : MonoBehaviour
public string jsonFileName = "mockDataNewConfig"; public string jsonFileName = "mockDataNewConfig";
public static Dictionary<string, GameObject> idToInstance = new(); public static Dictionary<string, GameObject> idToInstance = new();
public static bool _skipControlLibraryCalls = false; public static bool _skipControlLibraryCalls = true;
public static bool SkipControlLibraryCalls => _skipControlLibraryCalls; public static bool SkipControlLibraryCalls => _skipControlLibraryCalls;
@@ -58,7 +58,7 @@ public class TopologyBuilder : MonoBehaviour
graph.Connections.Add(new Connection { FromModuleId = fromId, ToModuleId = toId, FromSocket = c.FromSocket ?? "MaleSocket", ToSocket = c.ToSocket ?? "FemaleSocket", Orientation = o }); graph.Connections.Add(new Connection { FromModuleId = fromId, ToModuleId = toId, FromSocket = c.FromSocket ?? "MaleSocket", ToSocket = c.ToSocket ?? "FemaleSocket", Orientation = o });
} }
Debug.Log($"[TopologyBuilder] Built from JSON: {jsonFileName}"); Debug.Log($"[TopologyBuilder] Built from JSON: {jsonFileName}");
_skipControlLibraryCalls = skipControlLibraryCalls; _skipControlLibraryCalls = true;
} }
else else
{ {

View File

@@ -8,6 +8,8 @@ public abstract class ModuleBase : MonoBehaviour
public abstract string moduleType { get; } public abstract string moduleType { get; }
public abstract string moduleName { get; } public abstract string moduleName { get; }
private static bool _nativeLibFailed = false;
public void SendToControlLibrary(string moduleType, float currentAngle) public void SendToControlLibrary(string moduleType, float currentAngle)
{ {
int angleRounded = Mathf.RoundToInt(currentAngle); int angleRounded = Mathf.RoundToInt(currentAngle);
@@ -37,13 +39,31 @@ public abstract class ModuleBase : MonoBehaviour
}); });
} }
Debug.Log($"[ControlLibrary] Sending command: {json}"); Debug.Log($"[ControlLibrary] Sending command: {json}");
if (TopologyBuilder.SkipControlLibraryCalls) if (TopologyBuilder.SkipControlLibraryCalls || _nativeLibFailed)
{ {
return; return;
} }
try
{
if (0 != ControlLibrary.send_angle_control(Int32.Parse(moduleID), angleRounded)) if (0 != ControlLibrary.send_angle_control(Int32.Parse(moduleID), angleRounded))
{ {
Debug.Log("Control library exited with error"); Debug.Log("Control library exited with error");
} }
} }
catch (DllNotFoundException)
{
Debug.LogWarning("[ControlLibrary] Native library libc_control not found. Disabling further native calls.");
_nativeLibFailed = true;
}
catch (EntryPointNotFoundException)
{
Debug.LogWarning("[ControlLibrary] Entry point not found in libc_control. Disabling further native calls.");
_nativeLibFailed = true;
}
catch (Exception e)
{
Debug.LogWarning($"[ControlLibrary] Native call failed: {e.Message}");
_nativeLibFailed = true;
}
}
} }

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using TMPro;
/// <summary> /// <summary>
/// Controller for ProgrammedMovements view: timeline banner at bottom. /// Controller for ProgrammedMovements view: timeline banner at bottom.
@@ -271,11 +271,12 @@ public class ProgrammedMovementsController : MonoBehaviour
{ {
var go = new GameObject(); var go = new GameObject();
go.transform.SetParent(parent, false); go.transform.SetParent(parent, false);
var tmp = go.AddComponent<TextMeshProUGUI>(); var txt = go.AddComponent<Text>();
tmp.text = text; txt.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
tmp.fontSize = fontSize; txt.text = text;
tmp.color = Color.white; txt.fontSize = fontSize;
tmp.alignment = TextAlignmentOptions.Center; txt.color = Color.white;
txt.alignment = TextAnchor.MiddleCenter;
go.AddComponent<RectTransform>(); go.AddComponent<RectTransform>();
return go; return go;
} }
@@ -373,7 +374,7 @@ public class ProgrammedMovementsController : MonoBehaviour
var mod = (ModuleBase)block.moduleServo ?? block.moduleDC; var mod = (ModuleBase)block.moduleServo ?? block.moduleDC;
var moduleLabel = config.Find("ConfigRow1/ModuleLabel") ?? config.Find("ModuleLabel"); var moduleLabel = config.Find("ConfigRow1/ModuleLabel") ?? config.Find("ModuleLabel");
var ml = moduleLabel?.GetComponent<TextMeshProUGUI>(); var ml = moduleLabel?.GetComponent<Text>();
if (ml != null) ml.text = mod != null ? GetModuleTypeName(mod) : "None"; if (ml != null) ml.text = mod != null ? GetModuleTypeName(mod) : "None";
var row2 = config.Find("ConfigRow2"); var row2 = config.Find("ConfigRow2");
@@ -389,18 +390,18 @@ public class ProgrammedMovementsController : MonoBehaviour
if (!isDC) if (!isDC)
{ {
var ai = angleInput?.GetComponent<TMP_InputField>(); var ai = angleInput?.GetComponent<InputField>();
if (ai != null) ai.text = block.targetAngle.ToString("F0"); if (ai != null) ai.text = block.targetAngle.ToString("F0");
} }
else else
{ {
if (dirButtons != null) UpdateDirectionButtonsVisual(dirButtons, block.dcDirection); if (dirButtons != null) UpdateDirectionButtonsVisual(dirButtons, block.dcDirection);
var dcd = dcDegreesInput?.GetComponent<TMP_InputField>(); var dcd = dcDegreesInput?.GetComponent<InputField>();
if (dcd != null) dcd.text = block.targetAngle.ToString("F0"); if (dcd != null) dcd.text = block.targetAngle.ToString("F0");
} }
var secondInput = config.Find("ConfigRow2/SecondInput") ?? config.Find("SecondInput"); var secondInput = config.Find("ConfigRow2/SecondInput") ?? config.Find("SecondInput");
var si = secondInput?.GetComponent<TMP_InputField>(); var si = secondInput?.GetComponent<InputField>();
if (si != null) si.text = block.second.ToString(); if (si != null) si.text = block.second.ToString();
} }
@@ -408,7 +409,7 @@ public class ProgrammedMovementsController : MonoBehaviour
{ {
var config = _configView?.Find("ConfigContent"); var config = _configView?.Find("ConfigContent");
var moduleLabel = config?.Find("ConfigRow1/ModuleLabel") ?? config?.Find("ModuleLabel"); var moduleLabel = config?.Find("ConfigRow1/ModuleLabel") ?? config?.Find("ModuleLabel");
var ml = moduleLabel?.GetComponent<TextMeshProUGUI>(); var ml = moduleLabel?.GetComponent<Text>();
if (ml != null) ml.text = text; if (ml != null) ml.text = text;
} }
@@ -496,18 +497,18 @@ public class ProgrammedMovementsController : MonoBehaviour
if (block.moduleDC == null) if (block.moduleDC == null)
{ {
var angleInput = config.Find("ConfigRow2/AngleSection/AngleInput") ?? config.Find("ConfigRow2/AngleInput") ?? config.Find("AngleInput"); var angleInput = config.Find("ConfigRow2/AngleSection/AngleInput") ?? config.Find("ConfigRow2/AngleInput") ?? config.Find("AngleInput");
if (angleInput != null && float.TryParse(angleInput.GetComponent<TMP_InputField>()?.text, out float angle)) if (angleInput != null && float.TryParse(angleInput.GetComponent<InputField>()?.text, out float angle))
block.targetAngle = Mathf.Clamp(angle, 0f, 180f); block.targetAngle = Mathf.Clamp(angle, 0f, 180f);
} }
else else
{ {
var dcDegreesInput = directionSection?.Find("DCDegreesInput"); var dcDegreesInput = directionSection?.Find("DCDegreesInput");
if (dcDegreesInput != null && float.TryParse(dcDegreesInput.GetComponent<TMP_InputField>()?.text, out float degrees)) if (dcDegreesInput != null && float.TryParse(dcDegreesInput.GetComponent<InputField>()?.text, out float degrees))
block.targetAngle = Mathf.Clamp(degrees, 1f, 3600f); block.targetAngle = Mathf.Clamp(degrees, 1f, 3600f);
} }
var secondInput = config.Find("ConfigRow2/SecondInput") ?? config.Find("SecondInput"); var secondInput = config.Find("ConfigRow2/SecondInput") ?? config.Find("SecondInput");
if (secondInput != null && int.TryParse(secondInput.GetComponent<TMP_InputField>()?.text, out int sec)) if (secondInput != null && int.TryParse(secondInput.GetComponent<InputField>()?.text, out int sec))
{ {
UnindexBlock(_editingBlock); UnindexBlock(_editingBlock);
_editingBlock.second = Mathf.Clamp(sec, 0, TimelineDurationSeconds - 1); _editingBlock.second = Mathf.Clamp(sec, 0, TimelineDurationSeconds - 1);
@@ -522,14 +523,16 @@ public class ProgrammedMovementsController : MonoBehaviour
go.transform.SetParent(parent, false); go.transform.SetParent(parent, false);
var img = go.AddComponent<Image>(); var img = go.AddComponent<Image>();
img.color = new Color(0.2f, 0.2f, 0.25f, 1f); img.color = new Color(0.2f, 0.2f, 0.25f, 1f);
var input = go.AddComponent<TMP_InputField>(); var input = go.AddComponent<InputField>();
var textGO = new GameObject("Text"); var textGO = new GameObject("Text");
textGO.transform.SetParent(go.transform, false); textGO.transform.SetParent(go.transform, false);
var text = textGO.AddComponent<TextMeshProUGUI>(); var text = textGO.AddComponent<Text>();
text.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
text.text = initial; text.text = initial;
text.fontSize = 11; text.fontSize = 11;
text.color = Color.white; text.color = Color.white;
text.alignment = TextAlignmentOptions.Center; text.alignment = TextAnchor.MiddleCenter;
text.horizontalOverflow = HorizontalWrapMode.Overflow;
var textRect = textGO.GetComponent<RectTransform>(); var textRect = textGO.GetComponent<RectTransform>();
textRect.anchorMin = Vector2.zero; textRect.anchorMin = Vector2.zero;
textRect.anchorMax = Vector2.one; textRect.anchorMax = Vector2.one;
@@ -615,8 +618,8 @@ public class ProgrammedMovementsController : MonoBehaviour
if (runButton != null) if (runButton != null)
{ {
runButton.interactable = true; runButton.interactable = true;
var tmp = runButton.GetComponentInChildren<TextMeshProUGUI>(); var txt = runButton.GetComponentInChildren<Text>();
if (tmp != null) tmp.text = _isRunning ? "Running" : "Run"; if (txt != null) txt.text = _isRunning ? "Running" : "Run";
} }
} }

View File

@@ -0,0 +1,79 @@
{
"Modules": [
{ "Id": "splitter1", "Type": "Splitter4", "Degree": null },
{ "Id": "battery1", "Type": "Battery", "Degree": null },
{ "Id": "servo1", "Type": "Servo1", "Degree": 45 },
{ "Id": "servo2", "Type": "Servo2", "Degree": 60 },
{ "Id": "servo3", "Type": "Servo1", "Degree": 90 },
{ "Id": "servo4", "Type": "Servo2", "Degree": 45 },
{ "Id": "servo5", "Type": "Servo1", "Degree": 120 },
{ "Id": "servo6", "Type": "Servo2", "Degree": 30 },
{ "Id": "endModule", "Type": "Gripper", "Degree": null },
{ "Id": "dc1", "Type": "DC", "Degree": null }
],
"Connections": [
{
"FromModuleId": "splitter1",
"ToModuleId": "battery1",
"FromSocket": "MaleSocket1",
"ToSocket": "FemaleSocket",
"Orientation": 0
},
{
"FromModuleId": "battery1",
"ToModuleId": "servo1",
"FromSocket": "MaleSocket",
"ToSocket": "BodySocket",
"Orientation": 0
},
{
"FromModuleId": "servo1",
"ToModuleId": "servo2",
"FromSocket": "MaleSocket",
"ToSocket": "FemaleSocket",
"Orientation": 90
},
{
"FromModuleId": "servo2",
"ToModuleId": "servo3",
"FromSocket": "MaleSocket",
"ToSocket": "FemaleSocket",
"Orientation": 0
},
{
"FromModuleId": "servo3",
"ToModuleId": "servo4",
"FromSocket": "MaleSocket",
"ToSocket": "FemaleSocket",
"Orientation": 90
},
{
"FromModuleId": "servo4",
"ToModuleId": "servo5",
"FromSocket": "MaleSocket",
"ToSocket": "FemaleSocket",
"Orientation": 0
},
{
"FromModuleId": "servo5",
"ToModuleId": "servo6",
"FromSocket": "MaleSocket",
"ToSocket": "FemaleSocket",
"Orientation": 90
},
{
"FromModuleId": "servo6",
"ToModuleId": "endModule",
"FromSocket": "MaleSocket",
"ToSocket": "FemaleSocket",
"Orientation": 0
},
{
"FromModuleId": "splitter1",
"ToModuleId": "dc1",
"FromSocket": "MaleSocket2",
"ToSocket": "FemaleSocket",
"Orientation": 0
}
]
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: df0412505158d4319bb0b04fa712883a
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,9 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro;
public class SelectedModuleLabelController : MonoBehaviour public class SelectedModuleLabelController : MonoBehaviour
{ {
public TextMeshProUGUI selectedModuleText; public Text selectedModuleText;
void Update() void Update()
{ {

View File

@@ -1,11 +1,11 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro; using UnityEngine.EventSystems;
public class ServoModuleUISliderController : MonoBehaviour public class ServoModuleUISliderController : MonoBehaviour
{ {
public Slider angleSlider; public Slider angleSlider;
public TextMeshProUGUI selectedModuleText; public Text selectedModuleText;
private bool isDragging = false; private bool isDragging = false;
@@ -14,27 +14,38 @@ public class ServoModuleUISliderController : MonoBehaviour
if (angleSlider == null) if (angleSlider == null)
angleSlider = GetComponentInChildren<Slider>(); angleSlider = GetComponentInChildren<Slider>();
if (angleSlider == null) return;
angleSlider.minValue = 0f; angleSlider.minValue = 0f;
angleSlider.maxValue = 180f; angleSlider.maxValue = 180f;
angleSlider.onValueChanged.AddListener(OnSliderChanged); angleSlider.onValueChanged.AddListener(OnSliderChanged);
var et = angleSlider.GetComponent<EventTrigger>() ?? angleSlider.gameObject.AddComponent<EventTrigger>();
var begin = new EventTrigger.Entry { eventID = EventTriggerType.BeginDrag };
begin.callback.AddListener(_ => isDragging = true);
et.triggers.Add(begin);
var end = new EventTrigger.Entry { eventID = EventTriggerType.EndDrag };
end.callback.AddListener(_ => isDragging = false);
et.triggers.Add(end);
} }
void Update() void Update()
{ {
if (selectedModuleText == null || angleSlider == null) return;
var selected = ServoMotorModule.selectedModule; var selected = ServoMotorModule.selectedModule;
if (selected != null) if (selected != null)
{ {
selectedModuleText.text = $"Selected: {selected.name} | Angle: {selected.currentAngle:F1}°"; selectedModuleText.text = $"Selected: {selected.name} | Angle: {selected.currentAngle:F1}°";
// Sync slider with angle if not dragging
if (!isDragging) if (!isDragging)
{ {
angleSlider.value = selected.currentAngle; angleSlider.SetValueWithoutNotify(selected.currentAngle);
} }
// Make slider visible and interactable
if (!angleSlider.gameObject.activeSelf) if (!angleSlider.gameObject.activeSelf)
{ {
angleSlider.gameObject.SetActive(true); angleSlider.gameObject.SetActive(true);
@@ -44,7 +55,6 @@ public class ServoModuleUISliderController : MonoBehaviour
{ {
selectedModuleText.text = "No module selected"; selectedModuleText.text = "No module selected";
// Hide slider when no module selected
if (angleSlider.gameObject.activeSelf) if (angleSlider.gameObject.activeSelf)
{ {
angleSlider.gameObject.SetActive(false); angleSlider.gameObject.SetActive(false);
@@ -59,9 +69,4 @@ public class ServoModuleUISliderController : MonoBehaviour
ServoMotorModule.selectedModule.SetAngleAndSendControlLibrary(value); ServoMotorModule.selectedModule.SetAngleAndSendControlLibrary(value);
} }
} }
public void OnEndDrag()
{
isDragging = false;
}
} }

View File

@@ -1,6 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro;
/// <summary> /// <summary>
/// Top banner with three buttons (1=Live View, 2=Inverse Kinematics, 3=Programmed Movements). /// Top banner with three buttons (1=Live View, 2=Inverse Kinematics, 3=Programmed Movements).
@@ -163,13 +162,14 @@ public class ViewBannerUI : MonoBehaviour
textRect.offsetMin = new Vector2(6, 4); textRect.offsetMin = new Vector2(6, 4);
textRect.offsetMax = new Vector2(-6, -4); textRect.offsetMax = new Vector2(-6, -4);
var tmp = textGo.AddComponent<TextMeshProUGUI>(); var txt = textGo.AddComponent<Text>();
tmp.text = label; txt.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
tmp.fontSize = 18; txt.text = label;
tmp.fontStyle = FontStyles.Bold; txt.fontSize = 18;
tmp.alignment = TextAlignmentOptions.Center; txt.fontStyle = FontStyle.Bold;
tmp.color = buttonTextColor; txt.alignment = TextAnchor.MiddleCenter;
tmp.enableWordWrapping = true; txt.color = buttonTextColor;
txt.horizontalOverflow = HorizontalWrapMode.Wrap;
return image; return image;
} }