using System.Collections; using System.Collections.Generic; using UnityEngine; public class TabButtonGroup { public delegate void TabSelectDelegate(int index); public TabButtonGroup.TabSelectDelegate OnSelect; private List m_TabList; public List TabList { get { return this.m_TabList; } set { this.m_TabList = value; } } public bool Enable { get; set; } public TabButtonGroup() { this.m_TabList = new List(); this.Enable = true; } public void Add(TabButton tab) { this.m_TabList.Add(tab); } public void Remove(TabButton tab) { this.m_TabList.Remove(tab); } public void Select(int index) { if (!this.Enable) { return; } for (int i = 0; i < this.m_TabList.Count; i++) { TabButton tabButton = this.m_TabList[i]; if (i == index) { tabButton.Selected = true; if (OnSelect != null) { OnSelect(i); } } else { tabButton.Selected = false; } } } public void Select(TabButton tab) { if (!this.Enable) { return; } for (int i = 0; i < this.m_TabList.Count; i++) { TabButton tabButton = this.m_TabList[i]; if (tabButton == tab) { tabButton.Selected = true; if (this.OnSelect != null) { this.OnSelect(i); } } else { tabButton.Selected = false; } } } public void OnDestroy() { this.m_TabList.Clear(); this.OnSelect = null; } public int GetTabCount() { return this.m_TabList.Count; } public TabButton GetTab(int index) { index = Mathf.Clamp(index, 0, this.m_TabList.Count - 1); return this.m_TabList[index]; } }