示例#1
0
        public UITab GetTab(int i)
        {
            UITab t = null;

            if (i < tabs.Length && tabs[i] != null)
            {
                t = tabs[i];
            }
            else if (i < tabPrefabs.Length)
            {
                Transform parent = container is PopupBase? (container as PopupBase).window.ui.transform: transform;
                t           = tabs[i] = tabPrefabs[i].InstantiateEx(parent);
                t.tabButton = tabButtons[i];
                t.tabButton.SetCallback(OnClickTab, t);
                UIWindow win = popupWindow;
                if (win != null)
                {
                    foreach (UIPanel p in t.uiRoot.GetComponentsInChildren <UIPanel>(true))
                    {
                        p.SetLayerOver(win.Panel);
                    }
                }
            }
            if (!t.isInitialized)
            {
                t.Init(container);
                t.tabButton.AddCallback(new Action <UITab>(OnClickTab), t);
                t.uiRoot.SetActive(false);
            }
            return(t);
        }
示例#2
0
 public void Init(MonoBehaviour container)
 {
     this.container = container;
     // resize tabs if not initialized
     if (tabs.Count < tabPrefabs.Length)
     {
         var newTabs = new List <UITab>(tabPrefabs.Length);
         newTabs.AddRange(tabs);
         tabs = newTabs;
     }
     for (int i = 0; i < tabs.Count; ++i)
     {
         if (tabs[i] != null)
         {
             UITab t = GetTab(i);
             t.tabButton.SetCallback(OnClickTab, t);
             if (currentTab == null)
             {
                 currentTab = t;
             }
         }
         else
         {
             tabButtons[i].SetCallback(CreateTab, tabPrefabs[i]);
         }
     }
     initialized = true;
 }
示例#3
0
 public void Init(MonoBehaviour container)
 {
     this.container = container;
     // resize tabs if not initialized
     if (tabs.Length < tabPrefabs.Length)
     {
         UITab[] newTabs = new UITab[tabPrefabs.Length];
         Array.Copy(tabs, newTabs, tabs.Length);
         tabs = newTabs;
     }
     for (int i = 0; i < tabs.Length; ++i)
     {
         if (tabs[i] != null)
         {
             UITab t = GetTab(i);
             t.tabButton.SetCallback(OnClickTab, t);
             if (currentTab == null)
             {
                 currentTab = t;
             }
         }
         else
         {
             tabButtons[i].SetCallback(CreateTab, tabPrefabs[i]);
         }
     }
     initialized = true;
 }
示例#4
0
        private void OnTabRemoved(Object o, int index)
        {
            UITab tab = o as UITab;

            if (tab == null || tab.tabButton == null)
            {
                return;
            }
            EventDelegateUtil.RemoveCallback <UITab>(tab.tabButton.onClick, tabHandler, tabHandler.OnClickTab, tab);
        }
示例#5
0
 public void CloseAndResetTab()
 {
     for (int i = 0; i < tabs.Length; ++i)
     {
         if (tabs[i] != null)
         {
             currentTab = tabs[i];
             break;
         }
     }
     Close();
 }
示例#6
0
        public void SetActiveTab(int index)
        {
            UITab t = GetTab(index);

            if (t != null)
            {
                OnClickTab(t);
            }
            else
            {
                UITab.log.Error("Tab index out of range {0} >= {1}", index, tabs.Length);
            }
        }
示例#7
0
 public void OnClickTab(UITab tab)
 {
     if (checkTabMove != null)
     {
         checkTabMove(tab, () => {
             _OnClickTab(tab);
         });
     }
     else
     {
         _OnClickTab(tab);
     }
 }
示例#8
0
        private void OnTabChanged(Object o, int index)
        {
            UITab tab = o as UITab;

            if (tab == null)
            {
                return;
            }
            if (tab.tabButton != null)
            {
                EventDelegateUtil.AddCallback <UITab>(tab.tabButton.onClick, tabHandler.OnClickTab, tab);
            }
        }
示例#9
0
 public void _OnClickTab(UITab tab)
 {
     currentTab = tab;
     if (!initialized)
     {
         return;
     }
     foreach (UITab t in tabs)
     {
         if (t != null && t != currentTab)
         {
             t.SetVisible(false);
         }
     }
     currentTab.SetVisible(true);
     tabCallback.Call(currentTab);
 }
示例#10
0
 private void SetTab()
 {
     foreach (GameObject o in Selection.gameObjects)
     {
         UIButton tab     = null;
         UITab    tabRoot = o.GetComponent <UITab>();
         if (tabRoot != null)
         {
             tab = tabRoot.tabButton;
         }
         else
         {
             tab = o.GetComponent <UIButton>();
         }
         if (tab != null)
         {
             tab.normalSprite   = "tab_on";
             tab.hoverSprite    = null;
             tab.pressedSprite  = null;
             tab.disabledSprite = null;
             UIButtonColor[] colors = tab.GetComponents <UIButtonColor>();
             if (colors.Length < 2)
             {
                 UIButtonColor c     = tabRoot.tabButton.gameObject.AddComponent <UIButtonColor>();
                 UILabel       label = tabRoot.tabButton.GetComponentInChildren <UILabel>();
                 c.tweenTarget = label.gameObject;
             }
             foreach (UIButtonColor c in tab.GetComponents <UIButtonColor>())
             {
                 c.tweenTarget.GetComponent <UIWidget>().color = INACTIVE_TAB_COLOR;
                 c.hover         = INACTIVE_TAB_COLOR;
                 c.pressed       = INACTIVE_TAB_COLOR;
                 c.disabledColor = ACTIVE_TAB_COLOR;
             }
             EditorUtil.SetDirty(tab.gameObject);
         }
     }
 }
示例#11
0
        public void CreateTab(UITab tab)
        {
            int index = tabPrefabs.FindIndex(tab);

            OnClickTab(GetTab(index));
        }