コード例 #1
0
        private void InitializePages()
        {
            if (m_Pages.Length > 0)
            {
                for (int i = 0; i < m_Pages.Length; i++)
                {
                    m_Pages[i].gameObject.SetActive(true);
                }
            }

            m_PageSize = m_PagesRect.GetProperSize();

            for (int i = 0; i < m_Pages.Length; i++)
            {
                RectTransform page = m_Pages[i].rectTransform;

                page.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, i * m_PageSize.x, m_PageSize.x);
            }

            m_PagesContainer.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, m_PageSize.x * m_Pages.Length);

            OverscrollConfig overscrollConfig = m_PagesRect.GetComponent <OverscrollConfig>();

            if (overscrollConfig != null)
            {
                overscrollConfig.Setup();
            }

            SetPage(m_CurrentPage, false);
        }
コード例 #2
0
        protected override void OnEnable()
        {
            base.OnEnable();
            RegisterEvents();
            OverscrollConfig overscrollConfig = GetComponentInChildren <OverscrollConfig>();

            if (overscrollConfig != null)
            {
                overscrollConfig.Setup();
            }
        }
コード例 #3
0
        public virtual void InitializePages()
        {
            if (this == null || m_PagesRect == null || !Application.isPlaying)
            {
                return;
            }

            if (pages.Count > 0)
            {
                for (int i = 0; i < pages.Count; i++)
                {
                    pages[i].gameObject.SetActive(true);
                }
            }

            m_PageSize = m_PagesRect.GetProperSize();

            for (int i = 0; i < pages.Count; i++)
            {
                RectTransform page = pages[i].rectTransform;

                page.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, i * m_PageSize.x, m_PageSize.x);
                page.anchorMin = Vector2.zero;
                page.anchorMax = new Vector2(0, 1);
                page.sizeDelta = new Vector2(page.sizeDelta.x, 0);
            }

            m_PagesContainer.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, m_PageSize.x * pages.Count);
            m_PagesContainer.anchorMin = Vector2.zero;
            m_PagesContainer.anchorMax = new Vector2(0, 1);
            m_PagesContainer.sizeDelta = new Vector2(m_PagesContainer.sizeDelta.x, 0);

            OverscrollConfig overscrollConfig = m_PagesRect.GetComponent <OverscrollConfig>();

            if (overscrollConfig != null)
            {
                overscrollConfig.Setup();
            }

            SetPage(m_CurrentPage, false);
        }
コード例 #4
0
        public virtual void InitializeTabs()
        {
            if (this == null || m_TabsContainer == null || !Application.isPlaying)
            {
                return;
            }

            var contentSizeFitter = m_TabsContainer.GetComponent <ContentSizeFitter>();

            if (contentSizeFitter != null)
            {
                contentSizeFitter.enabled = true;
            }

            //Initialize TabContainer
            m_TabsContainer.anchorMin = Vector2.zero;
            m_TabsContainer.anchorMax = new Vector2(0, 1);

            SetupTabSize();
            InstantiateTabsFromTemplate();

            var barParent = m_TabsContainer.parent as RectTransform;
            //Setup Size
            var tabContainerLayoutElement = m_TabsContainer.GetComponent <LayoutElement>();

            if (tabContainerLayoutElement)
            {
                tabContainerLayoutElement.minWidth = barParent.GetProperSize().x;//Mathf.Max(barWidth, tabContainerLayoutElement.minWidth, barParent != null? barParent.GetProperSize().x : 0);
            }
            //Configure Overscroll
            OverscrollConfig overscrollConfig = m_TabsContainer.parent.GetComponent <OverscrollConfig>();

            if (overscrollConfig != null)
            {
                overscrollConfig.Setup();
            }

            //Fix Indicator size in next cycle
            InitializeIndicatorDelayed();
        }
コード例 #5
0
        private void InitializePages()
        {
            if (m_Pages.Length > 0)
            {
                for (int i = 0; i < m_Pages.Length; i++)
                {
                    m_Pages[i].gameObject.SetActive(true);
                }
            }

            m_PageSize = m_PagesRect.GetProperSize();

            for (int i = 0; i < m_Pages.Length; i++)
            {
                RectTransform page = m_Pages[i].rectTransform;

                page.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, i * m_PageSize.x, m_PageSize.x);
            }

            m_PagesContainer.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, m_PageSize.x * m_Pages.Length);

            OverscrollConfig overscrollConfig = m_PagesRect.GetComponent <OverscrollConfig>();

            if (overscrollConfig != null)
            {
                overscrollConfig.Setup();
            }

            SetPage(m_CurrentPage, false);

            m_OnPageChanged.Invoke(m_CurrentPage);                        // Added by Pavan Jakhu
            AppBarController app = FindObjectOfType <AppBarController>(); // Added by Pavan Jakhu

            if (app != null)
            {
                app.SetTitle(pages[m_CurrentPage].tabName); // Added by Pavan Jakhu
            }
        }
コード例 #6
0
        public void InitializeTabs()
        {
            if (m_AlreadyInitialized)
            {
                for (int i = 0; i < m_Tabs.Length; i++)
                {
                    Destroy(m_Tabs[i].gameObject);
                }
                m_TabItemTemplate.gameObject.SetActive(true);
                LayoutRebuilder.ForceRebuildLayoutImmediate(rectTransform);
            }

            float barWidth = rectTransform.GetProperSize().x;

            m_TabWidth = GetMaxTabTextWidth() + (2 * m_TabPadding);

            m_TabsContainer.GetComponent <LayoutElement>().minWidth    = barWidth;
            m_TabsContainer.GetComponent <ContentSizeFitter>().enabled = true;

            float combinedWidth = m_TabWidth * m_Pages.Length;

            m_TabsContainer.GetComponent <HorizontalLayoutGroup>().childForceExpandWidth = true;
            m_TabItemTemplate.GetComponent <LayoutElement>().minWidth = 72;

            if (Screen.width > Screen.height && !m_ForceStretchTabsOnLanscape)
            {
                if (Mathf.Abs(combinedWidth - barWidth) < m_ShrinkTabsToFitThreshold)
                {
                    m_TabWidth = barWidth / m_Pages.Length;
                }
                else
                {
                    m_TabsContainer.GetComponent <HorizontalLayoutGroup>().childForceExpandWidth = false;
                    m_TabItemTemplate.GetComponent <LayoutElement>().minWidth = 160;
                }
            }
            else
            {
                if (combinedWidth - barWidth < m_ShrinkTabsToFitThreshold)
                {
                    m_TabWidth = barWidth / m_Pages.Length;
                }
            }

            m_TabWidth = Mathf.Max(m_TabWidth, m_TabItemTemplate.GetComponent <LayoutElement>().minWidth);

            m_TabItemTemplate.GetComponent <LayoutElement>().preferredWidth = m_TabWidth;
            m_Indicator.anchorMin = new Vector2(0, 0);
            m_Indicator.anchorMax = new Vector2(0, 0);
            m_Indicator.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, m_TabWidth);

            m_Tabs = new TabItem[m_Pages.Length];

            for (int i = 0; i < m_Pages.Length; i++)
            {
                TabItem tab = Instantiate(m_TabItemTemplate.gameObject).GetComponent <TabItem>();

                tab.rectTransform.SetParent(m_TabItemTemplate.transform.parent);

                tab.rectTransform.localScale       = Vector3.one;
                tab.rectTransform.localEulerAngles = Vector3.zero;
                tab.rectTransform.localPosition    = new Vector3(tab.rectTransform.localPosition.x, tab.rectTransform.localPosition.y, 0f);

                tab.id = i;

                if (!string.IsNullOrEmpty(m_Pages[i].tabName))
                {
                    tab.name = m_Pages[i].tabName;
                    if (tab.itemText != null)
                    {
                        tab.itemText.text = tab.name.ToUpper();
                    }
                }
                else
                {
                    tab.name = "Tab " + i;
                    if (tab.itemText != null)
                    {
                        tab.itemText.enabled = false;
                    }
                }

                tab.SetupGraphic(m_Pages[i].tabIcon.imageDataType);

                if (tab.itemIcon != null)
                {
                    if (m_Pages[i].tabIcon != null)
                    {
                        tab.itemIcon.SetImage(m_Pages[i].tabIcon);
                    }
                    else
                    {
                        tab.itemIcon.enabled = false;
                    }
                }

                m_Tabs[i] = tab;
            }

            m_TabItemTemplate.gameObject.SetActive(false);

            m_TabsContainer.anchorMin = Vector2.zero;
            m_TabsContainer.anchorMax = new Vector2(0, 1);

            OverscrollConfig overscrollConfig = m_TabsContainer.parent.GetComponent <OverscrollConfig>();

            if (overscrollConfig != null)
            {
                overscrollConfig.Setup();
            }

            m_AlreadyInitialized = true;
        }
コード例 #7
0
        public override void InitializeTabs()
        {
            if (this == null || m_TabsContainer == null || !Application.isPlaying)
            {
                return;
            }

            var contentSizeFitter = m_TabsContainer.GetComponent <ContentSizeFitter>();

            if (contentSizeFitter != null)
            {
                contentSizeFitter.enabled = true;
            }

            //Initialize TabContainer
            var layoutGroup = m_TabsContainer.GetComponent <HorizontalOrVerticalLayoutGroup>();

            if (layoutGroup != null && m_UseLegacyControlMode)
            {
                if (_cachedTabChildForceExpand == null)
                {
                    _cachedTabChildForceExpand = layoutGroup.childForceExpandWidth;
                }
                if (_cachedTabSpacing == null)
                {
                    _cachedTabSpacing = layoutGroup.spacing;
                }
                layoutGroup.childForceExpandWidth = m_ForceSameTabSize ? true : _cachedTabChildForceExpand.Value;
                layoutGroup.spacing = m_ForceSameTabSize ? 0 : _cachedTabSpacing.Value;
            }

            m_TabsContainer.anchorMin = Vector2.zero;
            m_TabsContainer.anchorMax = new Vector2(0, 1);

            SetupTabSize();
            InstantiateTabsFromTemplate();

            float barWidth = m_ForceSameTabSize ? (m_TabWidth * m_Pages.Count()) :
                             ((m_TabWidth + (layoutGroup != null ? layoutGroup.spacing : 0)) * m_Pages.Count()) + layoutGroup.padding.horizontal;

            var barParent = m_TabsContainer.parent as RectTransform;
            //Setup Size
            var tabContainerLayoutElement = m_TabsContainer.GetComponent <LayoutElement>();

            if (tabContainerLayoutElement)
            {
                tabContainerLayoutElement.minWidth = barParent.GetProperSize().x;//Mathf.Max(barWidth, tabContainerLayoutElement.minWidth, barParent != null? barParent.GetProperSize().x : 0);
            }
            m_TabsContainer.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, barWidth);

            //Configure Overscroll
            OverscrollConfig overscrollConfig = m_TabsContainer.parent.GetComponent <OverscrollConfig>();

            if (overscrollConfig != null)
            {
                overscrollConfig.Setup();
            }

            //Fix Indicator size in next cycle
            InitializeIndicatorDelayed();
        }