public void GoToScreen(UIScreen _nextScreen, object _object) { if (_nextScreen != null) { UIDebug.PrintDebug(UIDebug.DebugType.SCREEN, transform, "UIManager", "GoToScreen", "Go to UI Screen " + _nextScreen.name); int nextLayer = _nextScreen.layer; // add current screen to history // if current screen exist if (_currentScreens[_currentLayer]) { // and if we dont open the same screen again if (_currentScreens[_currentLayer] != _nextScreen) { // and if this screen have permission to add to history if (_currentScreens[_currentLayer].archive) { // then add it to history array _historyStack.Add(_currentScreens[_currentLayer]); } } } // close all screens from current layer and smaller to next layer without this one want to open // if actual open smaller or equal layer than was opened if (_currentLayer >= nextLayer) { int i = _currentLayer; do { // if screen exist in current array is equal it is open if (_currentScreens[i]) { // if screen is not this want to open if (_currentScreens[i] != _nextScreen) { // close it _currentScreens[i].CloseScreen(); // and clear place in current array _currentScreens[i] = null; } } i--; } while (i >= nextLayer); } // open next screen // if we dont open the same screen again //if (_currentScreen[nextLayer] != _nextScreen) //{ // set opening screen to current array on his layer _currentScreens[nextLayer] = _nextScreen; // just in case active gameObject _currentScreens[nextLayer].gameObject.SetActive(true); // set object on "Top" in hierarchy _currentScreens[nextLayer].transform.SetAsLastSibling(); // open screen with parameter _object _currentScreens[nextLayer].OpenScreen(_object); //} // set new current layer _currentLayer = nextLayer; // if are any events then invoke them if (onSwitchedScreen != null) { try { UIDebug.PrintDebug(UIDebug.DebugType.EVENT, transform, "UIManager", "On Switched Screen", "Event invoke."); onSwitchedScreen.Invoke(); } catch (System.Exception exception) { Debug.LogError("Couldn't invoke event OnSwitchedScreen in " + name + ". Error: " + exception.Message); } } } }
public void GoToScreen(UIScreen _nextScreen) { GoToScreen(_nextScreen, null); }