using UnityEngine; using UnityEngine.UI; public class DiscoverOverlayController : MonoBehaviour { public GameObject overlayPanel; public RectTransform overlayContent; public TopologyBuilder topologyBuilder; public void ShowOverlay() { if (overlayPanel == null) return; EnsureScrollRect(); ClearContent(); if (topologyBuilder == null) topologyBuilder = FindObjectOfType(); bool useMock = topologyBuilder != null && topologyBuilder.mockControlLibrary; if (useMock) { PopulateMockLeaders(); } else { int[] leaders = null; try { leaders = ControlLibrary.getRobotLeaders(); } catch (System.Exception ex) { Debug.LogError($"[Discover] getRobotLeaders failed: {ex.Message}"); } if (leaders != null && leaders.Length > 0) PopulateLeaders(leaders); else CreateLabel("No leaders found. Is the hardware connected?"); } overlayPanel.SetActive(true); } public void HideOverlay() { ClearContent(); if (overlayPanel != null) overlayPanel.SetActive(false); } void PopulateLeaders(int[] leaderIds) { float buttonHeight = 60f; float spacing = 10f; Font font = Resources.GetBuiltinResource("LegacyRuntime.ttf"); for (int i = 0; i < leaderIds.Length; i++) { int leaderId = leaderIds[i]; GameObject btnGo = new GameObject($"LeaderBtn_{leaderId}", typeof(RectTransform)); btnGo.transform.SetParent(overlayContent, false); RectTransform rt = btnGo.GetComponent(); rt.anchorMin = new Vector2(0.05f, 1f); rt.anchorMax = new Vector2(0.95f, 1f); rt.pivot = new Vector2(0.5f, 1f); rt.anchoredPosition = new Vector2(0f, -(spacing + i * (buttonHeight + spacing))); rt.sizeDelta = new Vector2(0f, buttonHeight); Image bg = btnGo.AddComponent(); bg.color = new Color(0.2f, 0.2f, 0.2f, 1f); Button btn = btnGo.AddComponent