123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TabButtonGroup
- {
- public delegate void TabSelectDelegate(int index);
- public TabButtonGroup.TabSelectDelegate OnSelect;
- private List<TabButton> m_TabList;
- public List<TabButton> TabList
- {
- get
- {
- return this.m_TabList;
- }
- set
- {
- this.m_TabList = value;
- }
- }
- public bool Enable
- {
- get;
- set;
- }
- public TabButtonGroup()
- {
- this.m_TabList = new List<TabButton>();
- 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];
- }
- }
|