Example #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(UIScreenId screenId)
        {
            GameObject screenPrefab = GetPrefabFromScreenId(screenId);

            if (screenPrefab != null)
            {
                // Instantiate the screen in the canvas.
                GameObject instantiatedPrefab = GameObject.Instantiate(screenPrefab, mCanvas.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);
        }
Example #2
0
        /// <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(UIScreenId screenId)
        {
            // if this is a new screen... (it should always be.)
            if (screenId != UIScreenId.None)
            {
                mInputLock = true;
                bool canNavigateBackwards = false;

                if (mCurrentScreen != null)
                {
                    canNavigateBackwards = mCurrentScreen.CanNavigateBack;
                    yield return(StartCoroutine(mCurrentScreen.DoScreenAnimation(UIScreenAnimState.Outro)));

                    UnloadCurrentScreen();
                }

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

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

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

                    mCurrentScreen = loadedScreen;

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

                    // Fire the 3d background animation.
                    UIManager.Instance.Transition3dCamera(mCurrentScreen.BackgroundState);

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

                    mCurrentScreen.SetPrompts();
                }
                mInputLock = false;
            }
        }
Example #3
0
        /// <summary>
        /// Returns the prefab associated with a screen id.
        /// </summary>
        /// <param name="screenId"></param>
        /// <returns></returns>
        private GameObject GetPrefabFromScreenId(UIScreenId screenId)
        {
            GameObject screenPrefab = null;

            if (screenId != UIScreenId.None)
            {
                UIScreenPrefabInfo info = mPrefabInfo.Find(p => p.ScreenId == screenId);
                screenPrefab = info.Prefab;
                return(screenPrefab);
            }

            Debug.AssertFormat(true, "{0} : Couldn't find a prefab for screenid : {1}. Make sure it is serialzied in mPrefabInfo.", UIManager.Identifier, screenId.ToString());
            return(screenPrefab);
        }
Example #4
0
        /// <summary>
        /// Handle UI Navigation Input
        /// </summary>
        /// <param name="buttonInfo"></param>
        public void OnUIInput(UIButtonInfo buttonInfo)
        {
            if (!mInputLock)
            {
                switch (buttonInfo.NavType)
                {
                case UINavigationType.Advance:
                    UIScreenId toScreen = buttonInfo.AdvanceScreen;
                    TransitionToScreen(toScreen);
                    break;

                case UINavigationType.Back:
                    DoBackTransition();
                    break;

                case UINavigationType.None:
                    break;

                default:
                    break;
                }
            }
        }
Example #5
0
 /// <summary>
 /// Transition to a screen id.
 /// </summary>
 /// <param name="screenId"></param>
 public void TransitionToScreen(UIScreenId screenId)
 {
     StartCoroutine(DoScreenTransition(screenId));
 }