using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; namespace AppUI.Util.TabSwitcher { public class UITabSwitcher : MonoBehaviour { [System.Serializable] public class TabItem { public string tabId; [Header("按钮")] public GameObject btn; [Header("标题")] public TMP_Text label; [Header("内容页")] public GameObject panel; [Header("默认允许显示")] public bool defaultVisible = true; } [SerializeField] List tabs = new(); [Header("默认Tab")] [SerializeField] string defaultTab; [Header("文字颜色")] [SerializeField] Color selectColor = Color.white; [SerializeField] Color normalColor = new Color32(153, 153, 153, 255); Dictionary tabMap = new(); void Awake() { Init(); } public void SetDefaultTab(string tabId) { defaultTab = tabId; } void Init() { tabMap.Clear(); foreach (var tab in tabs) { if (tab == null || string.IsNullOrEmpty(tab.tabId)) continue; tabMap[tab.tabId] = tab; if (tab.btn != null) { tab.btn.SetActive(tab.defaultVisible); // 自动绑定按钮事件 Button btn = tab.btn.GetComponent