Ejemplo n.º 1
0
        public int GetTabIndex(string tabID)
        {
            if (PanelNotificationCenter.TryGetTab(tabID, out PanelTab tab))
            {
                return(GetTabIndex(tab));
            }

            return(-1);
        }
Ejemplo n.º 2
0
        private static IPanelGroupElement Deserialize(PanelCanvas canvas, ISerializedElement element)
        {
            if (element == null)
            {
                return(null);
            }

            if (element is SerializedDummyPanel)
            {
                return(canvas.Internal.DummyPanel);
            }

            if (element is SerializedPanel serializedPanel)
            {
                Panel panel = null;

                SerializedPanelTab[] tabs = serializedPanel.tabs;
                for (int i = 0; i < tabs.Length; i++)
                {
                    if (!PanelNotificationCenter.TryGetTab(tabs[i].id, out PanelTab tab))
                    {
                        continue;
                    }

                    if (panel == null)
                    {
                        panel = tab.Detach();
                        canvas.UnanchoredPanelGroup.AddElement(panel);
                    }
                    else
                    {
                        panel.AddTab(tab);
                    }
                }

                if (panel != null)
                {
                    if (serializedPanel.activeTab < tabs.Length)
                    {
                        int activeTabIndex = panel.GetTabIndex(tabs[serializedPanel.activeTab].id);
                        if (activeTabIndex >= 0)
                        {
                            panel.ActiveTab = activeTabIndex;
                        }
                    }

                    if (serializedPanel is SerializedUnanchoredPanel unanchoredPanel)
                    {
                        panel.RectTransform.anchoredPosition = unanchoredPanel.position;
                        panel.gameObject.SetActive(unanchoredPanel.active);
                    }

                    panel.FloatingSize = serializedPanel.floatingSize;
                }

                return(panel);
            }

            if (element is SerializedPanelGroup serializedPanelGroup)
            {
                ISerializedElement[] children = serializedPanelGroup.children;
                if (children == null || children.Length == 0)
                {
                    return(null);
                }

                PanelGroup panelGroup = new PanelGroup(canvas, serializedPanelGroup.horizontal ? PanelDirection.Right : PanelDirection.Top);
                for (int i = 0; i < children.Length; i++)
                {
                    if (children[i] == null)
                    {
                        continue;
                    }

                    IPanelGroupElement childElement = Deserialize(canvas, children[i]);
                    if (childElement != null)
                    {
                        panelGroup.AddElement(childElement);
                        sizesHolder.Add(new GroupElementSizeHolder(childElement, children[i].size));
                    }
                }

                if (panelGroup.Count > 0)
                {
                    return(panelGroup);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public void RemoveTab(string tabID)
        {
            PanelNotificationCenter.TryGetTab(tabID, out PanelTab tab);

            RemoveTab(tab);
        }
Ejemplo n.º 4
0
        public PanelTab AddTab(string tabID)
        {
            PanelNotificationCenter.TryGetTab(tabID, out PanelTab tab);

            return(AddTab(tab));
        }