private void OnTabClick(UITab tab) { int index = -1; for (int i = tabs.Length - 1; i >= 0; --i) { if (tabs[i] == tab) { index = i; break; } } int oldSelect = curSelect; for (int i = listOnTabClick.Count - 1; i >= 0; --i) { listOnTabClick[i].Invoke(index); } if (oldSelect != index) { if (LocalCanTabSelect(index)) { SetSelect(index); } } }
public void Init(int selected = 0) { GameObject[] gos = gameObject.GetChildren(true); int count = gos == null ? 0 : gos.Length; tabs = new UITab[count]; for (int i = 0; i < count; i++) { tabs[i] = gos[i].AddComponentOnce <UITab>(); tabs[i].Init(i); tabs[i].IsSelected = (selected == i); tabs[i].onTabChange += OnTabClick; } curSelect = selected; }