예제 #1
0
        /// <summary>
        /// Creates a custom tab.
        /// </summary>
        /// <param name="helper">The <see cref="UIHelper"/>.</param>
        /// <param name="tabstrip">The <see cref="UITabstrip"/> this tab should belong to.</param>
        /// <param name="panelTemplate">The panel template.</param>
        /// <param name="buttonWidth">The width of the tab button.</param>
        /// <param name="title">The title of the tab.</param>
        /// <returns>A <see cref="UIHelper"/> object of the newly created tab.</returns>
        public static UIHelper AddCustomTab(this UIHelper helper, UITabstrip tabstrip, UIPanel panelTemplate, float buttonWidth, string title)
        {
            var tabstripGo = GameObject.Find(GameObjectDefs.ID_KEYMAPPING_TABSTRIP); //TODO(earalov): replace with custom code

            if (tabstripGo == null)
            {
                return(helper);
            }
            UITabstrip keyMappingTabstrip = tabstripGo.GetComponent <UITabstrip>();
            UIButton   buttonTemplate     = null;

            if (keyMappingTabstrip != null)
            {
                buttonTemplate = keyMappingTabstrip.GetComponentInChildren <UIButton>();
            }

            UIButton tabButton = tabstrip.AddCustomTab(title, buttonTemplate, panelTemplate, true);

            tabButton.playAudioEvents   = buttonTemplate.playAudioEvents;
            tabButton.pressedTextColor  = buttonTemplate.pressedTextColor;
            tabButton.focusedTextColor  = buttonTemplate.focusedTextColor;
            tabButton.disabledTextColor = buttonTemplate.disabledTextColor;
            tabButton.width             = buttonWidth;

            UIPanel           tab           = tabstrip.tabPages.components.Last() as UIPanel;
            UIScrollablePanel scrollableTab = tab.GetComponentInChildren <UIScrollablePanel>();

            if (scrollableTab != null)
            {
                scrollableTab.autoLayout          = true;
                scrollableTab.autoLayoutDirection = LayoutDirection.Vertical;
                scrollableTab.autoLayoutPadding   = new RectOffset(0, 0, 2, 0);
                return(new UIHelper(scrollableTab));
            }
            else
            {
                tab.autoLayout          = true;
                tab.autoLayoutDirection = LayoutDirection.Vertical;
                tab.autoLayoutPadding   = new RectOffset(0, 0, 2, 0);
                return(new UIHelper(tab));
            }
        }