private Panel CreateInitialPanel(PanelProperties properties, Panel anchor, PanelDirection anchorDirection, HashSet <Transform> createdTabs) { Panel panel = null; for (int i = 0; i < properties.tabs.Count; i++) { PanelTabProperties panelProps = properties.tabs[i]; if (panelProps.content) { if (createdTabs.Contains(panelProps.content)) { continue; } if (panelProps.content.parent != RectTransform) { panelProps.content.SetParent(RectTransform, false); } PanelTab tab; if (panel == null) { panel = PanelUtils.CreatePanelFor(panelProps.content, this, panelPrefab); tab = panel[0]; } else { tab = panel.AddTab(panelProps.content); } tab.Icon = panelProps.tabIcon; tab.Label = panelProps.tabLabel; tab.MinSize = panelProps.minimumSize; tab.ID = panelProps.id; createdTabs.Add(panelProps.content); } } if (panel != null) { panel.ActiveTab = 0; if (anchor != null && anchorDirection != PanelDirection.None) { panel.DockToPanel(anchor, anchorDirection); } } return(panel); }
public PanelTab AddTab(RectTransform tabContent, int tabIndex = -1) { if (!tabContent) { return(null); } // Reset active tab because otherwise, it acts buggy in rare cases if (activeTab >= 0 && activeTab < tabs.Count) { tabs[activeTab].Internal.SetActive(false); } activeTab = -1; if (tabIndex < 0 || tabIndex > tabs.Count) { tabIndex = tabs.Count; } int thisTabIndex = GetTabIndex(tabContent); if (thisTabIndex == -1) { PanelTab tab = PanelUtils.GetAssociatedTab(tabContent); if (!tab) { tab = Instantiate(tabPrefab, tabsParent, false); tabs.Insert(tabIndex, tab); tabContent.anchorMin = Vector2.zero; tabContent.anchorMax = Vector2.one; tabContent.sizeDelta = Vector2.zero; tabContent.anchoredPosition = Vector2.zero; tabContent.localScale = Vector3.one; } else { tabs.Insert(tabIndex, tab); tab.Internal.rectTransform.SetParent(null, false); // workaround for a rare internal Unity crash tab.Internal.rectTransform.SetParent(tabsParent, false); tab.Panel.Internal.RemoveTab(tab.Index, false); } tab.Internal.Initialize(this, tabContent); tab.Internal.rectTransform.SetSiblingIndex(tabIndex); tabContent.SetParent(null, false); // workaround for a rare internal Unity crash tabContent.SetParent(contentParent, false); Internal.RecalculateMinSize(); } else if (thisTabIndex != tabIndex) { if (tabIndex == tabs.Count) { tabIndex = tabs.Count - 1; } PanelTab tab = tabs[thisTabIndex]; tab.Internal.rectTransform.SetSiblingIndex(tabIndex); tabs.RemoveAt(thisTabIndex); tabs.Insert(tabIndex, tab); } ActiveTab = tabIndex; return(tabs[tabIndex]); }