コード例 #1
0
    /// <summary>
    /// Loads a screen based on it's screen id.
    /// </summary>
    /// <param name="screenId">Unique identifier for a screen.</param>
    private UIBaseScreen LoadScreen(ScreenId screenId)
    {
        GameObject screenPrefab = GetPrefabFromScreenId(screenId);

        if (screenPrefab != null)
        {
            // Instantiate the screen in the canvas.
            GameObject instantiatedPrefab = GameObject.Instantiate(screenPrefab, m_Canvas.transform);

            if (instantiatedPrefab != null)
            {
                UIBaseScreen screen = instantiatedPrefab.GetComponent <UIBaseScreen>();

                if (screen != null)
                {
                    // Call set defaults and assign the current screen.
                    screen.Initialize();

                    return(screen);
                }
            }
        }

        return(null);
    }
コード例 #2
0
    public UIBaseScreen ShowScreen(UIBaseScreen screen, bool force = false)
    {
        if (screen == null)
        {
            throw new KeyNotFoundException("UIScreenManager: Show(UIBaseScreen) failed, screen is Null.");
        }

        if (!force && (mScreenQueueDirty || screenQueue.LastOrDefault() == screen))
        {
            return(screen);
        }

        screenQueue.Add(screen);
        InsertionSort(screenQueue);

        if (CurrentScreen == null || (int)CurrentScreen.Priority <= (int)screen.Priority)
        {
            if (CurrentScreen != null)
            {
                CurrentScreen.OnDeactivated(false);
            }
            mScreenQueueDirty = true;
        }

        return(screen);
    }
コード例 #3
0
ファイル: UIManager.cs プロジェクト: TheAngryCurtain/PSOesque
    /// <summary>
    /// Loads a screen based on it's screen id.
    /// </summary>
    /// <param name="screenId">Unique identifier for a screen.</param>
    private UIBaseScreen LoadScreen(ScreenId screenId)
    {
        GameObject screenPrefab = GetPrefabFromScreenId(screenId);

        if (screenPrefab != null)
        {
            // Instantiate the screen in the canvas.
            GameObject instantiatedPrefab = GameObject.Instantiate(screenPrefab, m_Canvas.transform);

            if (instantiatedPrefab != null)
            {
                UIBaseScreen screen = instantiatedPrefab.GetComponent <UIBaseScreen>();

                if (screen != null)
                {
                    // Call set defaults and assign the current screen.
                    screen.Initialize(m_ScreenParams);

                    // make sure prompts bar is last in the hierarchy
                    m_PromptsBar.SetAsLastSibling();

                    return(screen);
                }
            }
        }

        return(null);
    }
コード例 #4
0
 public void HideAllAndShow(string screenName)
 {
     if (!mListScreen.ContainsKey(screenName))
     {
         throw new KeyNotFoundException("ScreenManager: HideAllAndShow failed. Screen with name '" + screenName + "' does not exist.");
     }
     HideAll();
     mScreenToShowInTheEnd = mListScreen[screenName];
 }
コード例 #5
0
    public void Hide()
    {
        if (!mScreenQueueDirty && CurrentScreen != null && CurrentScreen.Transition)
        {
            return;
        }

        mScreenToKill     = CurrentScreen;
        mScreenQueueDirty = true;
    }
コード例 #6
0
ファイル: UIManager.cs プロジェクト: KXue/LDJam46
    public void LoadScreen(eScreens screen)
    {
        if (m_CurrentScreen != null)
        {
            m_CurrentScreen.Shutdown();
            GameObject.Destroy(m_CurrentScreen.gameObject);
        }

        m_CurrentScreen = GameObject.Instantiate(m_ScreenPrefabs[(int)screen], this.transform, false).GetComponent <UIBaseScreen>();
        m_CurrentScreen.Init();
    }
コード例 #7
0
ファイル: UIManager.cs プロジェクト: TheAngryCurtain/PSOesque
    /// <summary>
    /// Transition Work Enumerator.
    /// Carries out the screen loading process and locks the system until a screen has been loaded.
    /// </summary>
    /// <param name="screenId"></param>
    /// <returns></returns>
    private IEnumerator DoScreenTransition(ScreenId screenId)
    {
        // if this is a new screen... (it should always be.)
        if (screenId != ScreenId.None)
        {
            m_InputLock = true;
            bool canNavigateBackwards = false;

            if (m_CurrentScreen != null)
            {
                canNavigateBackwards = m_CurrentScreen.CanNavigateBack;
                m_PromptsBarAnimator.SetTrigger("Outro");

                yield return(StartCoroutine(m_CurrentScreen.DoScreenAnimation(UIScreenAnimState.Outro)));

                UnloadCurrentScreen();
            }

            m_PrefabLoadingLock = true;
            UIBaseScreen loadedScreen = LoadScreen(screenId);

            if (loadedScreen != null)
            {
                while (m_PrefabLoadingLock)
                {
                    yield return(null);
                }

                // If the current screen doesn't support back navigation, remove it from the stack.
                if (!canNavigateBackwards && m_ScreenStack.Count > 0)
                {
                    m_ScreenStack.Pop();
                }

                m_CurrentScreen = loadedScreen;

                // Back transitions can't add the screen twice.
                if (m_ScreenStack.Count == 0 || (m_ScreenStack.Count > 0 && screenId != m_ScreenStack.Peek()))
                {
                    // Push the new screen onto the stack.
                    m_ScreenStack.Push(screenId);
                }

                yield return(StartCoroutine(m_CurrentScreen.DoScreenAnimation(UIScreenAnimState.Intro)));

                ClearPrompts();

                m_CurrentScreen.SetPrompts(m_PromptsBar, m_PromptPrefab);
                m_PromptsBarAnimator.SetTrigger("Intro");
            }
            m_InputLock = false;
        }
    }
コード例 #8
0
    public override void Awake()
    {
        m_ScreenStack   = new Stack <ScreenId>();
        m_PopupStack    = new Stack <UIPopupData>();
        m_CurrentScreen = null;
        m_CurrentPopup  = null;

        Debug.AssertFormat(ValidateManager() != false, "{0} : Failed to validate, please ensure that all required components are set and not null.", UIManager.Identifier);

        m_Prompts = m_PromptsCanvas.GetComponent <UIPrompts>();

        base.Awake();
    }
コード例 #9
0
    private static int CompareBaseScreens(UIBaseScreen x, UIBaseScreen y)
    {
        int result = 1;

        if (x != null && x is UIBaseScreen &&
            y != null && y is UIBaseScreen)
        {
            UIBaseScreen screenX = (UIBaseScreen)x;
            UIBaseScreen screenY = (UIBaseScreen)y;
            result = screenX.CompareTo(screenY);
        }
        return(result);
    }
コード例 #10
0
    public void HideAll()
    {
        foreach (var item in screenQueue)
        {
            if (item == CurrentScreen)
            {
                continue;
            }
            item.SelectedObject = null;
            item.OnDeactivated(true, true);
        }
        screenQueue.Clear();

        mScreenToKill     = CurrentScreen;
        mScreenQueueDirty = true;
    }
コード例 #11
0
    private static void InsertionSort(IList <UIBaseScreen> list)
    {
        if (list.IsNullOrEmpty())
        {
            return;
        }

        int count = list.Count;

        for (int j = 1; j < count; j++)
        {
            UIBaseScreen key = list[j];

            int i = j - 1;
            for (; i >= 0 && CompareBaseScreens(list[i], key) > 0; i--)
            {
                list[i + 1] = list[i];
            }
            list[i + 1] = key;
        }
    }
コード例 #12
0
    IEnumerator CoroutineUpdate()
    {
        var waitTime = new WaitForSecondsRealtime(0.1f);

        while (true)
        {
            if (mScreenQueueDirty)
            {
                if (mScreenToKill != null && mScreenToKill == CurrentScreen)
                {
                    if (onScreenHide != null)
                    {
                        onScreenHide.Invoke(CurrentScreen);
                    }

                    int screenToKillIndex = screenQueue.FindLastIndex(x => x == mScreenToKill);
                    if (screenToKillIndex != -1)
                    {
                        screenQueue.RemoveAt(screenToKillIndex);
                    }

                    EventSystem.current.SetSelectedGameObject(null);
                    mScreenToKill.SelectedObject = null;
                    mScreenToKill.OnDeactivated(true, true);
                    if (mScreenToKill.keepOnTopWhenHiding)
                    {
                        mScreenToKeepOnTop = mScreenToKill;
                    }
                    mScreenToKill = null;
                    CurrentScreen = null;
                }

                if (screenQueue.Count == 0 && mScreenToShowInTheEnd != null)
                {
                    screenQueue.Add(mScreenToShowInTheEnd);
                    mScreenToShowInTheEnd = null;
                }

                UIBaseScreen maxPriorityScreen = screenQueue.LastOrDefault();

                if (CurrentScreen != maxPriorityScreen)
                {
                    UIBaseScreen previousScreen = CurrentScreen;

                    if (previousScreen != null)
                    {
                        previousScreen.SelectedObject = EventSystem.current.currentSelectedGameObject;
                        EventSystem.current.SetSelectedGameObject(null);
                    }

                    if (maxPriorityScreen.Transition)
                    {
                        CurrentScreen     = null;
                        mScreenQueueDirty = true;
                        yield return(waitTime);

                        continue;
                    }
                    else
                    {
                        CurrentScreen = maxPriorityScreen;

                        if (CurrentScreen == null && DefaultScreen != null)
                        {
                            CurrentScreen = DefaultScreen;
                        }

                        if (CurrentScreen != null)
                        {
                            if (onScreenShow != null)
                            {
                                onScreenShow.Invoke(CurrentScreen);
                            }
                            CurrentScreen.OnActivated();
                        }

                        if (previousScreen != null)
                        {
                            previousScreen.OnDeactivated(CurrentScreen.hideCurrent);
                        }

                        if (mScreenToKeepOnTop != null && mScreenToKeepOnTop.isActiveAndEnabled)
                        {
                            mScreenToKeepOnTop.transform.SetAsLastSibling();
                            mScreenToKeepOnTop = null;
                        }
                    }
                }

                mScreenQueueDirty = false;
            }

            if (!IsTouchMode && alwaysOnSelection)
            {
                if (CurrentScreen != null && !CurrentScreen.Transition)
                {
                    GameObject selectedGameObject = EventSystem.current.currentSelectedGameObject;
                    bool       isCurrentActive    = (selectedGameObject != null && selectedGameObject.activeInHierarchy);

                    if (!isCurrentActive)
                    {
                        if (lastSelection != null && lastSelection.activeInHierarchy && lastSelection.transform.IsChildOf(CurrentScreen.transform))
                        {
                            EventSystem.current.SetSelectedGameObject(lastSelection);
                        }
                        else if (CurrentScreen.DefaultSelection != null && CurrentScreen.DefaultSelection.gameObject.activeInHierarchy)
                        {
                            EventSystem.current.SetSelectedGameObject(CurrentScreen.DefaultSelection.gameObject);
                            lastSelection = CurrentScreen.DefaultSelection.gameObject;
                        }
                    }
                    else
                    {
                        lastSelection = selectedGameObject;
                    }
                }
            }

            yield return(waitTime);
        }
    }
コード例 #13
0
 public void Show(UIBaseScreen screen)
 {
     ShowScreen(screen);
 }
コード例 #14
0
 public void HideAllAndShow(UIBaseScreen screen)
 {
     HideAll();
     mScreenToShowInTheEnd = screen;
 }