private Panel CreateInitialPanel(PanelProperties properties, Panel anchor, Direction 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); 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 != Direction.None) { panel.DockToPanel(anchor, anchorDirection); } } return(panel); }
private Panel CreateInitialPanel(PanelProperties properties, Panel anchor, Direction anchorDirection, HashSet <Transform> createdTabs) { Panel panel = null; for (int i = 0; i < properties.tabs.Count; i++) { PanelTabProperties panelProps = properties.tabs[i]; if (panelProps.content != null && !panelProps.content.Equals(null)) { if (createdTabs.Contains(panelProps.content)) { continue; } if (panelProps.content.parent != RectTransform) { panelProps.content.SetParent(RectTransform, false); } int tabIndex = 0; if (panel == null) { panel = PanelUtils.CreatePanelFor(panelProps.content, this); } else { tabIndex = panel.AddTab(panelProps.content); } panel.SetTabTitle(tabIndex, panelProps.tabIcon, panelProps.tabLabel); panel.SetTabMinSize(tabIndex, panelProps.minimumSize); createdTabs.Add(panelProps.content); } } if (panel != null) { panel.ActiveTab = 0; if (anchor != null && anchorDirection != Direction.None) { panel.DockToPanel(anchor, anchorDirection); } } return(panel); }
public PanelTab AddTab(RectTransform tabContent, int tabIndex = -1) { if (tabContent == null || tabContent.Equals(null)) { return(null); } // Reset active tab because otherwise, it acts buggy in rare cases if (m_activeTab >= 0 && m_activeTab < tabs.Count) { tabs[m_activeTab].Internal.SetActive(false); } m_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 == null) { tab = (PanelTab)Instantiate(Resources.Load <PanelTab>("DynamicPanelTab"), 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]); }
public PanelTab AddTab(RectTransform tabContent, int tabIndex = -1) { if (!tabContent) { return(null); } // Reset active tab because otherwise, it acts buggy in rare cases if (m_activeTab >= 0 && m_activeTab < tabs.Count) { tabs[m_activeTab].Internal.SetActive(false); } m_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) { PanelTab panelTabPrefab = null; #if UNITY_EDITOR panelTabPrefab = Resources.Load <PanelTab>("DynamicPanelTab"); #else panelTabPrefab = GameObject.Find("BTDebugInspector").GetComponent <DesignerData>().DynamicPanelTab.GetComponent <PanelTab>(); #endif if (panelTabPrefab == null) { Debug.LogError("PanelTabPrefab is null"); } tab = (PanelTab)Instantiate(panelTabPrefab, 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]); }