using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class HotkeyUIController : MonoBehaviour { public static HotkeyUIController Instance; public GameObject hotkeyEntryPrefab; // Assign the HotkeyEntry prefab public Transform hotkeyListContainer; // Assign the Content transform of ScrollView public HotkeyManager hotkeyManager; private readonly Dictionary hotkeyEntries = new(); public void Awake() { if (Instance == null) Instance = this; else Destroy(gameObject); } // private void Start() // { // PopulateHotkeyList(); // } public void ClearChildren(Transform parentTransform) { // var parentTransform = parentObject.transform; // Detach all the children from the parent for (var i = parentTransform.childCount - 1; i >= 0; i--) { var childTransform = parentTransform.GetChild(i); childTransform.SetParent(null); } // Destroy all the detached children foreach (Transform child in parentTransform) Destroy(child.gameObject); } public void PopulateHotkeyList() { Debug.Log("Getting all hot keys"); var hotkeys = hotkeyManager.GetAllHotkeys(); Debug.Log("Clearing Children"); ClearChildren(hotkeyListContainer); foreach (var hotkey in hotkeys) { var entry = Instantiate(hotkeyEntryPrefab, hotkeyListContainer); var actionName = entry.transform.Find("ActionName").GetComponent(); var keyName = entry.transform.Find("KeyName").GetComponent(); var changeButton = entry.transform.Find("ChangeButton").GetComponent