Exemplo n.º 1
0
    /// <summary>
    /// Sets the currently active window to the given index
    /// </summary>
    /// <param name="index">The window to be set active</param>
    public void SwitchTabs(int index)
    {
        GameObject currentWindow = windows.FirstOrDefault(panel => panel.activeInHierarchy == true);

        if (currentWindow != null)
        {
            ViewportContent closingWindowController = currentWindow.GetComponent <ViewportContent>();

            if (closingWindowController != null)
            {
                closingWindowController.CloseWindow();
            }

            currentWindow.SetActive(false);
        }

        Button next = NextButton.GetComponent <Button>();
        Button back = BackButton.GetComponent <Button>();

        next.onClick.RemoveAllListeners();
        back.onClick.RemoveAllListeners();

        ViewportContent windowController = windows[index].GetComponent <ViewportContent>();

        if (windowController != null)
        {
            if (windowController.PageCount > 1 && windowController.UsePageCount)
            {
                NextButton.SetActive(true);
                BackButton.SetActive(true);
                next.onClick.AddListener(windowController.ScrollNext);
                back.onClick.AddListener(windowController.ScrollBack);
            }
            else
            {
                NextButton.SetActive(false);
                BackButton.SetActive(false);
            }

            windowController.OpenWindow();
        }
        else
        {
            NextButton.SetActive(false);
            BackButton.SetActive(false);
        }

        if (tabButtons.Length > 0)
        {
            Array.ForEach(tabButtons, obj => obj.SetHighLight(false));
            tabButtons[index].SetHighLight(true);
        }

        OntabSwitch?.Invoke(index);
        windows[index].SetActive(true);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Generates the windows by calling the SetupContent() method for each, if a controller is found
    /// </summary>
    private void GenerateWindows()
    {
        foreach (GameObject window in windows)
        {
            ResizeWindow(window.GetComponent <RectTransform>());
            ViewportContent windowController = window.GetComponent <ViewportContent>();

            if (windowController != null)
            {
                windowController.SetupContent(this, mainViewport);
                windowController.CloseWindow();
            }

            window.SetActive(false);
        }
    }