mirror of
https://github.com/BotChain-Robots/ui.git
synced 2026-07-08 15:07:22 +02:00
Fixed weird underline on UI text and made text bigger
Made-with: Cursor
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class AngleControllerSlider : MonoBehaviour
|
||||
{
|
||||
public GameObject angleUI;
|
||||
public Slider angleSlider;
|
||||
public TextMeshProUGUI angleLabel;
|
||||
public Text angleLabel;
|
||||
|
||||
private Transform currentCap;
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class BlockJointController : MonoBehaviour
|
||||
{
|
||||
public Transform rotatingCap;
|
||||
public Slider angleSlider;
|
||||
public TextMeshProUGUI angleLabel;
|
||||
public Text angleLabel;
|
||||
|
||||
private float currentAngle = 0f;
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ControlPanel : MonoBehaviour
|
||||
{
|
||||
[Header("Core UI (assign in Inspector)")]
|
||||
public TMP_InputField inputField;
|
||||
public TMP_Dropdown directionDropdown;
|
||||
public InputField inputField;
|
||||
public Dropdown directionDropdown;
|
||||
public Button button; // existing Send/Rotate button in hierarchy
|
||||
|
||||
private enum Mode { None, DC, Display, Speaker }
|
||||
@@ -20,17 +19,15 @@ public class ControlPanel : MonoBehaviour
|
||||
private int _savedDirectionIndex = 0;
|
||||
private string _savedDisplayInput = "";
|
||||
|
||||
// Found automatically (no hierarchy edits)
|
||||
private TextMeshProUGUI _caption; // child "DegreesCaption"
|
||||
private TextMeshProUGUI _buttonText; // child "RotateButton/Text (TMP)"
|
||||
private Text _caption; // child "DegreesCaption"
|
||||
private Text _buttonText; // child "RotateButton/Text (TMP)"
|
||||
private GameObject _directionCaptionGO;
|
||||
private GameObject _directionDropdownGO;
|
||||
|
||||
// Created in code (Speaker mode only)
|
||||
private Button _uploadButton;
|
||||
private TextMeshProUGUI _uploadButtonText;
|
||||
private Text _uploadButtonText;
|
||||
private Button _playButton;
|
||||
private TextMeshProUGUI _playButtonText;
|
||||
private Text _playButtonText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -91,10 +88,10 @@ public class ControlPanel : MonoBehaviour
|
||||
private void CacheUIFromHierarchy()
|
||||
{
|
||||
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)");
|
||||
if (buttonTextT != null) _buttonText = buttonTextT.GetComponent<TextMeshProUGUI>();
|
||||
if (buttonTextT != null) _buttonText = buttonTextT.GetComponent<Text>();
|
||||
|
||||
var dirCaptionT = transform.Find("DirectionCaption");
|
||||
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;
|
||||
|
||||
target.font = source.font;
|
||||
target.fontSharedMaterial = source.fontSharedMaterial;
|
||||
target.fontStyle = source.fontStyle;
|
||||
target.fontSize = source.fontSize;
|
||||
target.enableAutoSizing = source.enableAutoSizing;
|
||||
target.color = source.color;
|
||||
target.enableVertexGradient = source.enableVertexGradient;
|
||||
target.alignment = source.alignment;
|
||||
target.enableWordWrapping = source.enableWordWrapping;
|
||||
target.richText = source.richText;
|
||||
target.horizontalOverflow = source.horizontalOverflow;
|
||||
target.verticalOverflow = source.verticalOverflow;
|
||||
}
|
||||
|
||||
// -------------------------
|
||||
@@ -289,14 +283,13 @@ public class ControlPanel : MonoBehaviour
|
||||
// Copy Send button look
|
||||
CopyButtonStyle(button, _uploadButton);
|
||||
|
||||
var textGo = new GameObject("Text (TMP)");
|
||||
var textGo = new GameObject("Text");
|
||||
textGo.transform.SetParent(go.transform, false);
|
||||
_uploadButtonText = textGo.AddComponent<TextMeshProUGUI>();
|
||||
_uploadButtonText = textGo.AddComponent<Text>();
|
||||
_uploadButtonText.text = "Upload Audio";
|
||||
|
||||
// Copy Send text look
|
||||
CopyTMPStyle(_buttonText, _uploadButtonText);
|
||||
_uploadButtonText.alignment = TextAlignmentOptions.Center;
|
||||
CopyTextStyle(_buttonText, _uploadButtonText);
|
||||
_uploadButtonText.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
// Layout: above Play
|
||||
var rt = go.GetComponent<RectTransform>();
|
||||
@@ -353,14 +346,13 @@ public class ControlPanel : MonoBehaviour
|
||||
// Copy Send button look
|
||||
CopyButtonStyle(button, _playButton);
|
||||
|
||||
var textGo = new GameObject("Text (TMP)");
|
||||
var textGo = new GameObject("Text");
|
||||
textGo.transform.SetParent(go.transform, false);
|
||||
_playButtonText = textGo.AddComponent<TextMeshProUGUI>();
|
||||
_playButtonText = textGo.AddComponent<Text>();
|
||||
_playButtonText.text = "Play Audio";
|
||||
|
||||
// Copy Send text look
|
||||
CopyTMPStyle(_buttonText, _playButtonText);
|
||||
_playButtonText.alignment = TextAlignmentOptions.Center;
|
||||
CopyTextStyle(_buttonText, _playButtonText);
|
||||
_playButtonText.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
// Layout: between Upload and Send
|
||||
var rt = go.GetComponent<RectTransform>();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
@@ -30,17 +30,12 @@ public class DistanceSensorModule : ModuleBase
|
||||
|
||||
try
|
||||
{
|
||||
// Control library call
|
||||
double distance = ControlLibrary.get_distance_control(id);
|
||||
|
||||
infoLines[1] = $"Distance: {distance:F0} mm";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// SHOW THE PROBLEM ON SCREEN (works in release builds)
|
||||
infoLines[1] = $"EXCEPTION: {e.GetType().Name}: {e.Message}";
|
||||
|
||||
// Also log to Player.log (works in builds)
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class PositionControlGizmo : MonoBehaviour
|
||||
{
|
||||
[Header("Gizmo Settings")]
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
/// <summary>
|
||||
/// IK-mode side panel: shows fixed-module hint. Text is set in the scene.
|
||||
/// </summary>
|
||||
public class IKModulePanel : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI moduleInfoText;
|
||||
public Text moduleInfoText;
|
||||
|
||||
[Header("Panel Layout")]
|
||||
public float panelWidth = 260f;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
|
||||
public class LiveViewModulePanel : MonoBehaviour
|
||||
{
|
||||
[Header("Module Info")]
|
||||
public TextMeshProUGUI moduleInfoText;
|
||||
public Text moduleInfoText;
|
||||
|
||||
[Header("Servo Control")]
|
||||
public GameObject servoControlSection;
|
||||
public Slider servoAngleSlider;
|
||||
public TextMeshProUGUI servoAngleLabel;
|
||||
public Text servoAngleLabel;
|
||||
|
||||
[Header("DC + Display Control (Reused)")]
|
||||
public GameObject moduleControlSection;
|
||||
@@ -24,7 +24,7 @@ public class LiveViewModulePanel : MonoBehaviour
|
||||
private bool _sliderDragging;
|
||||
private ControlPanel panel;
|
||||
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()
|
||||
{
|
||||
@@ -170,10 +170,9 @@ public class LiveViewModulePanel : MonoBehaviour
|
||||
sensorTextContainer = new GameObject("SensorTextContainer");
|
||||
sensorTextContainer.transform.SetParent(parent, false);
|
||||
|
||||
var src = moduleInfoText.rectTransform;
|
||||
var src = moduleInfoText.GetComponent<RectTransform>();
|
||||
var rt = sensorTextContainer.AddComponent<RectTransform>();
|
||||
|
||||
// Place under the moduleInfoText
|
||||
rt.anchorMin = src.anchorMin;
|
||||
rt.anchorMax = src.anchorMax;
|
||||
rt.pivot = src.pivot;
|
||||
@@ -198,24 +197,16 @@ public class LiveViewModulePanel : MonoBehaviour
|
||||
var go = new GameObject($"SensorLine{sensorTextLines.Count}");
|
||||
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
|
||||
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;
|
||||
var rt = go.GetComponent<RectTransform>();
|
||||
rt.anchorMin = new Vector2(0f, 1f);
|
||||
rt.anchorMax = new Vector2(1f, 1f);
|
||||
rt.pivot = new Vector2(0f, 1f);
|
||||
@@ -225,10 +216,9 @@ public class LiveViewModulePanel : MonoBehaviour
|
||||
rt.anchoredPosition = new Vector2(0f, y);
|
||||
rt.sizeDelta = new Vector2(0f, lineH);
|
||||
|
||||
sensorTextLines.Add(tmp);
|
||||
sensorTextLines.Add(txt);
|
||||
}
|
||||
|
||||
// Hide extras
|
||||
for (int i = 0; i < sensorTextLines.Count; i++)
|
||||
sensorTextLines[i].gameObject.SetActive(i < count);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class TopologyBuilder : MonoBehaviour
|
||||
public string jsonFileName = "mockDataNewConfig";
|
||||
|
||||
public static Dictionary<string, GameObject> idToInstance = new();
|
||||
public static bool _skipControlLibraryCalls = false;
|
||||
public static bool _skipControlLibraryCalls = true;
|
||||
|
||||
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 });
|
||||
}
|
||||
Debug.Log($"[TopologyBuilder] Built from JSON: {jsonFileName}");
|
||||
_skipControlLibraryCalls = skipControlLibraryCalls;
|
||||
_skipControlLibraryCalls = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,6 +8,8 @@ public abstract class ModuleBase : MonoBehaviour
|
||||
public abstract string moduleType { get; }
|
||||
public abstract string moduleName { get; }
|
||||
|
||||
private static bool _nativeLibFailed = false;
|
||||
|
||||
public void SendToControlLibrary(string moduleType, float currentAngle)
|
||||
{
|
||||
int angleRounded = Mathf.RoundToInt(currentAngle);
|
||||
@@ -37,13 +39,31 @@ public abstract class ModuleBase : MonoBehaviour
|
||||
});
|
||||
}
|
||||
Debug.Log($"[ControlLibrary] Sending command: {json}");
|
||||
if (TopologyBuilder.SkipControlLibraryCalls)
|
||||
if (TopologyBuilder.SkipControlLibraryCalls || _nativeLibFailed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (0 != ControlLibrary.send_angle_control(Int32.Parse(moduleID), angleRounded))
|
||||
try
|
||||
{
|
||||
Debug.Log("Control library exited with error");
|
||||
if (0 != ControlLibrary.send_angle_control(Int32.Parse(moduleID), angleRounded))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Controller for ProgrammedMovements view: timeline banner at bottom.
|
||||
@@ -271,11 +271,12 @@ public class ProgrammedMovementsController : MonoBehaviour
|
||||
{
|
||||
var go = new GameObject();
|
||||
go.transform.SetParent(parent, false);
|
||||
var tmp = go.AddComponent<TextMeshProUGUI>();
|
||||
tmp.text = text;
|
||||
tmp.fontSize = fontSize;
|
||||
tmp.color = Color.white;
|
||||
tmp.alignment = TextAlignmentOptions.Center;
|
||||
var txt = go.AddComponent<Text>();
|
||||
txt.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
|
||||
txt.text = text;
|
||||
txt.fontSize = fontSize;
|
||||
txt.color = Color.white;
|
||||
txt.alignment = TextAnchor.MiddleCenter;
|
||||
go.AddComponent<RectTransform>();
|
||||
return go;
|
||||
}
|
||||
@@ -373,7 +374,7 @@ public class ProgrammedMovementsController : MonoBehaviour
|
||||
|
||||
var mod = (ModuleBase)block.moduleServo ?? block.moduleDC;
|
||||
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";
|
||||
|
||||
var row2 = config.Find("ConfigRow2");
|
||||
@@ -389,18 +390,18 @@ public class ProgrammedMovementsController : MonoBehaviour
|
||||
|
||||
if (!isDC)
|
||||
{
|
||||
var ai = angleInput?.GetComponent<TMP_InputField>();
|
||||
var ai = angleInput?.GetComponent<InputField>();
|
||||
if (ai != null) ai.text = block.targetAngle.ToString("F0");
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -408,7 +409,7 @@ public class ProgrammedMovementsController : MonoBehaviour
|
||||
{
|
||||
var config = _configView?.Find("ConfigContent");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -496,18 +497,18 @@ public class ProgrammedMovementsController : MonoBehaviour
|
||||
if (block.moduleDC == null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
_editingBlock.second = Mathf.Clamp(sec, 0, TimelineDurationSeconds - 1);
|
||||
@@ -522,14 +523,16 @@ public class ProgrammedMovementsController : MonoBehaviour
|
||||
go.transform.SetParent(parent, false);
|
||||
var img = go.AddComponent<Image>();
|
||||
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");
|
||||
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.fontSize = 11;
|
||||
text.color = Color.white;
|
||||
text.alignment = TextAlignmentOptions.Center;
|
||||
text.alignment = TextAnchor.MiddleCenter;
|
||||
text.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
var textRect = textGO.GetComponent<RectTransform>();
|
||||
textRect.anchorMin = Vector2.zero;
|
||||
textRect.anchorMax = Vector2.one;
|
||||
@@ -615,8 +618,8 @@ public class ProgrammedMovementsController : MonoBehaviour
|
||||
if (runButton != null)
|
||||
{
|
||||
runButton.interactable = true;
|
||||
var tmp = runButton.GetComponentInChildren<TextMeshProUGUI>();
|
||||
if (tmp != null) tmp.text = _isRunning ? "Running" : "Run";
|
||||
var txt = runButton.GetComponentInChildren<Text>();
|
||||
if (txt != null) txt.text = _isRunning ? "Running" : "Run";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
79
Assets/Resources/mockDataWithDC.json
Normal file
79
Assets/Resources/mockDataWithDC.json
Normal 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
|
||||
}
|
||||
]
|
||||
}
|
||||
7
Assets/Resources/mockDataWithDC.json.meta
Normal file
7
Assets/Resources/mockDataWithDC.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df0412505158d4319bb0b04fa712883a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,9 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using TMPro;
|
||||
|
||||
public class SelectedModuleLabelController : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI selectedModuleText;
|
||||
public Text selectedModuleText;
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class ServoModuleUISliderController : MonoBehaviour
|
||||
{
|
||||
public Slider angleSlider;
|
||||
public TextMeshProUGUI selectedModuleText;
|
||||
public Text selectedModuleText;
|
||||
|
||||
private bool isDragging = false;
|
||||
|
||||
@@ -14,27 +14,38 @@ public class ServoModuleUISliderController : MonoBehaviour
|
||||
if (angleSlider == null)
|
||||
angleSlider = GetComponentInChildren<Slider>();
|
||||
|
||||
if (angleSlider == null) return;
|
||||
|
||||
angleSlider.minValue = 0f;
|
||||
angleSlider.maxValue = 180f;
|
||||
|
||||
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()
|
||||
{
|
||||
if (selectedModuleText == null || angleSlider == null) return;
|
||||
|
||||
var selected = ServoMotorModule.selectedModule;
|
||||
|
||||
if (selected != null)
|
||||
{
|
||||
selectedModuleText.text = $"Selected: {selected.name} | Angle: {selected.currentAngle:F1}°";
|
||||
|
||||
// Sync slider with angle if not dragging
|
||||
if (!isDragging)
|
||||
{
|
||||
angleSlider.value = selected.currentAngle;
|
||||
angleSlider.SetValueWithoutNotify(selected.currentAngle);
|
||||
}
|
||||
|
||||
// Make slider visible and interactable
|
||||
if (!angleSlider.gameObject.activeSelf)
|
||||
{
|
||||
angleSlider.gameObject.SetActive(true);
|
||||
@@ -44,7 +55,6 @@ public class ServoModuleUISliderController : MonoBehaviour
|
||||
{
|
||||
selectedModuleText.text = "No module selected";
|
||||
|
||||
// Hide slider when no module selected
|
||||
if (angleSlider.gameObject.activeSelf)
|
||||
{
|
||||
angleSlider.gameObject.SetActive(false);
|
||||
@@ -59,9 +69,4 @@ public class ServoModuleUISliderController : MonoBehaviour
|
||||
ServoMotorModule.selectedModule.SetAngleAndSendControlLibrary(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEndDrag()
|
||||
{
|
||||
isDragging = false;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
/// <summary>
|
||||
/// 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.offsetMax = new Vector2(-6, -4);
|
||||
|
||||
var tmp = textGo.AddComponent<TextMeshProUGUI>();
|
||||
tmp.text = label;
|
||||
tmp.fontSize = 18;
|
||||
tmp.fontStyle = FontStyles.Bold;
|
||||
tmp.alignment = TextAlignmentOptions.Center;
|
||||
tmp.color = buttonTextColor;
|
||||
tmp.enableWordWrapping = true;
|
||||
var txt = textGo.AddComponent<Text>();
|
||||
txt.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
|
||||
txt.text = label;
|
||||
txt.fontSize = 18;
|
||||
txt.fontStyle = FontStyle.Bold;
|
||||
txt.alignment = TextAnchor.MiddleCenter;
|
||||
txt.color = buttonTextColor;
|
||||
txt.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user