1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using UnityEngine;
- using System.Collections;
- public class NavTab : DGUI {
- public CallBackUtil.IntegerCallBack OnNavTabChanged;
- public Transform tabContainer;
- public NavTabButton[] tabBtns;
- public ViewStack viewStack;
- private int currentIndex = int.MinValue;
- private string[] titleArr;
- protected virtual void Awake()
- {
- tabContainer = transform.FindChild ("Tabs");
- tabBtns = new NavTabButton[tabContainer.childCount];
- for(int i=0; i<tabBtns.Length; i++)
- {
- NavTabButton btn = tabContainer.GetChild (i).gameObject.AddComponent<NavTabButton>();
- btn.OnClick = OnTabBtnClick;
- btn.enabled = false;
- tabBtns [i] = btn;
- }
- SetTitles (titleArr);
- }
- protected virtual void Start()
- {
- if(currentIndex == int.MinValue)
- navTabIndex = 0;
- }
- public void SetTitles(string[] titleArr)
- {
- this.titleArr = titleArr;
- if (titleArr == null)
- return;
- for(int i=0; i<tabBtns.Length; i++)
- {
- tabBtns [i].label.text = titleArr [i];
- }
- }
- public int navTabIndex
- {
- set{
- OnTabBtnClick (value);
- }
- get{
- return currentIndex;
- }
- }
- public void UnSelected()
- {
- OnTabBtnClick (-1);
- }
- private void OnTabBtnClick(int index)
- {
- if (currentIndex == index)
- return;
- for(int i=0; i<tabBtns.Length; i++)
- {
- NavTabButton btn = tabBtns [i];
- btn.enabled = i == index ? true : false;
- }
- currentIndex = index;
- if (viewStack != null)
- viewStack.viewIndex = currentIndex;
- if (OnNavTabChanged != null)
- OnNavTabChanged (index);
- }
- }
|