/// <summary> /// Aligns the tabs to the given alignment. /// </summary> /// <param name="align"></param> public void AlignTabs(QUI_TabAlign align) { int tabCount = windows.Count; float tabsWidth = 0; tabAlign = align; for (int i = 0; i < tabCount; ++i) { RectTransform tabTransform; tabTransform = windows[i].tab.GetComponent <RectTransform>(); if (!tabTransform) { continue; } tabsWidth += tabTransform.rect.width; } float currentTabWidth = 0; for (int i = 0; i < tabCount; ++i) { QUI_TabWindow window = windows[i]; RectTransform tabTransform = window.tab.GetComponent <RectTransform>(); float tabWidth = tabTransform.rect.width; if (align == QUI_TabAlign.Left) { tabTransform.anchorMin = new Vector2(0, 1); tabTransform.anchorMax = new Vector2(0, 1); tabTransform.pivot = new Vector2(0, 0); tabTransform.anchoredPosition = new Vector2(currentTabWidth + sideOffset, 0); currentTabWidth += tabWidth; } else if (align == QUI_TabAlign.Center) { tabTransform.anchorMin = new Vector2(0.5f, 1); tabTransform.anchorMax = new Vector2(0.5f, 1); tabTransform.pivot = new Vector2(0.5f, 0); tabTransform.anchoredPosition = new Vector2(-tabsWidth / 2 + tabsWidth / 2 / tabCount + currentTabWidth, 0); currentTabWidth += tabWidth; } else if (align == QUI_TabAlign.Right) { currentTabWidth += tabWidth; tabTransform.anchorMin = new Vector2(1, 1); tabTransform.anchorMax = new Vector2(1, 1); tabTransform.pivot = new Vector2(1, 0); tabTransform.anchoredPosition = new Vector2(-tabsWidth + currentTabWidth - sideOffset, 0); } } }
/// <summary> /// Sets the active tab window of the group. /// </summary> /// <param name="window"></param> public void SetWindow(QUI_TabWindow window) { if (!windows.Contains(window)) { return; } if (currentWindow) { currentWindow.SetActive(false); } currentWindow = window; if (currentWindow) { currentWindow.SetActive(true); } }
public void Awake() { windows = new List <QUI_TabWindow>(GetComponentsInChildren <QUI_TabWindow>(true)); foreach (var window in windows) { if (window.startActive) { if (!currentWindow) { currentWindow = window; } else { window.startActive = false; } } window.tab.startActive = window.startActive; } }