Esempio n. 1
0
        private static void CreateAndCatalogueScreen(Screens screenType, string prefabLocation)
        {
            GameObject screenPrefab       = Resources.Load <GameObject>(prefabLocation) as GameObject;
            GameObject instantiatedScreen = GameObject.Instantiate(screenPrefab);

            instantiatedScreen.transform.SetParent(_canvasRootObject.transform, false);
            ScreenPanel screenPanel = instantiatedScreen.GetComponent <ScreenPanel>();

            _availableScreens.Add(screenType, screenPanel);
        }
Esempio n. 2
0
        public static void OpenPage(Screens screen, bool clearHistory = false)
        {
            if (screen == _currentScreen)
            {
                Debug.LogWarning("Attempted to open the same screen, aborting.");
                return;
            }

            if (_uiStack == null)
            {
                _uiStack = new Stack <Screens>();
            }

            ScreenPanel panel = null;

            _availableScreens.TryGetValue(screen, out panel);

            if (panel != null)
            {
                if (_uiStack.Count > 0)
                {
                    // we may need to delay showing the new screen until the old one calls back
                    _availableScreens[_uiStack.Peek()].HideScreen(_defaultDuration, () =>
                    {
                        _availableScreens[screen].ShowScreen();

                        if (clearHistory)
                        {
                            _uiStack.Clear();
                        }

                        _uiStack.Push(screen);
                        _currentScreen = screen;
                    });
                }
                else // we don't need to wait
                {
                    _availableScreens[screen].ShowScreen();

                    if (clearHistory)
                    {
                        _uiStack.Clear();
                    }

                    _uiStack.Push(screen);
                    _currentScreen = screen;
                }
            }
            else
            {
                Debug.LogError("'" + screen.ToString() + "' is not a valid screen.");
            }
        }