using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; namespace BITKit.UX { /// /// Tab容器,仅用于快速生成TabBar /// [UnityEngine.Scripting.Preserve] public class TabBar : VisualElement,INotifyValueChanged { public new class UxmlTraits:VisualElement.UxmlTraits { private readonly UxmlIntAttributeDescription m_TabBarAttribute = new () { name = "CurrentTab", defaultValue = -1 }; private readonly UxmlStringAttributeDescription m_TabsAttribute = new () { name = "tabs" }; private readonly UxmlBoolAttributeDescription m_allowFocus = new () { name = "allowFocus", defaultValue = true }; public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) { base.Init(ve, bag, cc); var tabBar = (TabBar)ve; tabBar.CurrentTab = m_TabBarAttribute.GetValueFromBag(bag, cc); tabBar.Tabs = m_TabsAttribute.GetValueFromBag(bag, cc); tabBar.allowFocus = m_allowFocus.GetValueFromBag(bag, cc); } } public new class UxmlFactory : UxmlFactory { } // These are USS class names for the control overall and the label. public TabBar() { RegisterCallback(UpdateI); RegisterCallback(UpdateI); RegisterCallback(UpdateI); } private void UpdateI(object _) { CurrentTab = _currentTab; } public event Action OnTabChanged; private Button[] _buttons = Array.Empty