Exemplo n.º 1
0
        public void SetSelection(string tabName)
        {
            if (!mInitialized)
            {
                return;
            }

            if (string.IsNullOrEmpty(tabName))
            {
                tabName = DefaultPanel;
            }

            for (int i = 0; i < Buttons.Count; i++)
            {
                GUITabButton tabButton = Buttons[i];
                if (tabButton.Name == tabName)
                {
                    tabButton.Selected = true;
                }
                else
                {
                    tabButton.Selected = false;
                }
            }
            mLastPage = tabName;
            OnSetSelection.SafeInvoke();
        }
Exemplo n.º 2
0
        public void OnClickButton(GUITabButton tabButton)
        {
            if (!mInitialized)
            {
                return;
            }

            SetSelection(tabButton.Name);
        }
Exemplo n.º 3
0
        public void Initialize(GUITabs tabParent, GUITabButton button)
        {
            if (mInitialized)
            {
                return;
            }

            NGUICamera  = tabParent.NGUICamera;
            TabParent   = tabParent;
            Button      = button;
            button.Page = this;
            UIPanel[] panels = gameObject.GetComponentsInChildren <UIPanel>(true);
            for (int i = 0; i < panels.Length; i++)
            {
                //make sure the panel isn't being managed by a sub-tab
                bool addPanel = true;
                for (int j = 0; j < TabParent.SubTabs.Count; j++)
                {
                    if (TabParent.SubTabs[j].ManagesPanel(panels[i]))
                    {
                        addPanel = false;
                    }
                }
                if (addPanel)
                {
                    Panels.Add(panels[i]);
                }
            }
            UIPanel mainPanel = null;

            if (gameObject.HasComponent <UIPanel>(out mainPanel))
            {
                Panels.SafeAdd(mainPanel);
            }

            Component[] tabPageChildren = gameObject.GetComponentsInChildren(typeof(IGUITabPageChild), true);
            for (int i = 0; i < tabPageChildren.Length; i++)
            {
                IGUITabPageChild tabPageChild = tabPageChildren[i] as IGUITabPageChild;
                Children.Add(tabPageChild);
            }

            OnSelected       += Show;
            OnDeselected     += Hide;
            TabParent.OnHide += Hide;

            mInitialized = true;
        }
Exemplo n.º 4
0
 public bool GetNextButton(GUITabButton current, out GUITabButton next)
 {
     next = null;
     if (Visible)
     {
         if (current == null && Buttons.Count > 0)
         {
             next = Buttons[0];
         }
         else
         {
             for (int i = 0; i < Buttons.Count; i++)
             {
                 if (Buttons[i].Name == current.Name && i < Buttons.LastIndex())
                 {
                     next = Buttons[i + 1];
                     break;
                 }
             }
         }
     }
     return(next != null);
 }
Exemplo n.º 5
0
        public void Initialize(IGUITabOwner owner)
        {
            if (owner == this)
            {
                Debug.Log("TABS CANNOT OWN THEMSELVES IN " + name);
                return;
            }

            Owner         = owner;
            Owner.OnShow += Show;
            Owner.OnHide += Hide;
            NGUICamera    = owner.NGUICamera;
            Buttons.Clear();
            Pages.Clear();

            foreach (Transform child in transform)
            {
                GUITabButton tabButton = null;
                if (child.gameObject.HasComponent <GUITabButton>(out tabButton))
                {
                    tabButton.name = name + "-" + tabButton.Name;
                    Buttons.Add(tabButton);
                }

                GUITabPage page = null;
                if (child.gameObject.HasComponent <GUITabPage>(out page))
                {
                    page.NGUICamera = NGUICamera;
                    Pages.Add(page);
                    GUITabs subTabs = null;
                    if (child.gameObject.HasComponent <GUITabs>(out subTabs))
                    {
                        page.SubTabs       = subTabs;
                        subTabs.NGUICamera = NGUICamera;
                        subTabs.ParentTabs = this;
                        subTabs.Initialize(this);
                        SubTabs.Add(subTabs);
                    }
                }
            }

            //sort the buttons
            Buttons.Sort();

            for (int i = 0; i < Pages.Count; i++)
            {
                for (int j = 0; j < Buttons.Count; j++)
                {
                    if (Pages[i].name == Buttons[j].Name)
                    {
                        Pages[i].NGUICamera = NGUICamera;
                        Pages[i].Initialize(this, Buttons[j]);
                        Buttons[j].Initialize(this, Pages[i]);
                    }
                }
            }

            for (int i = 0; i < Buttons.Count; i++)
            {
                if (!Buttons[i].Initialized)
                {
                    Buttons[i].Initialize(this, null);
                }
            }

            mInitialized = true;

            if (Visible)
            {
                Show();
            }
            else
            {
                Hide();
            }
        }