private void OnOpenScreenRequest(OpenScreenRequestSignal signal) { // First check if the type of screen is already opened (unless it's forced by setting the 'ForceOpen' property) if (!signal.ForceOpen) { var screenExistsInNavigationStack = _navigationStack.Any(item => item.Type == signal.Type); if (screenExistsInNavigationStack) { return; // If the type of screen does exists in the navigation stack we ignore the request } } var screenController = _screenFactory.Create(signal.Type); // Blur the previous screen (if there is one) if (_navigationStack.Count > 0) { _navigationStack.Last().ScreenController.Blur(); } // Push the new screen to the navigation stack and 'open' it var newScreenStackItem = new ScreenStackItem { Type = signal.Type, ScreenController = screenController }; _navigationStack.Push(newScreenStackItem); // Focus the new screen screenController.Focus(); _currentFocussed = newScreenStackItem; screenController.Open(); }
private void OnCloseScreenRequest(CloseScreenRequestSignal signal) { var subjectScreenStackItem = _navigationStack.FirstOrDefault(screenStackItem => screenStackItem.ScreenController == signal.ScreenController); if (subjectScreenStackItem == null) { Debug.LogWarningFormat("Trying to close a screen '{0}', but it doesn't exist in the navigation stack!", signal.ScreenController.GetType().ToString()); return; } // If the closed screen was the screen in front, focus the next screen var frontScreen = _navigationStack.Last(); if (signal.ScreenController == frontScreen.ScreenController) { var newFrontScreenStackItem = _navigationStack[_navigationStack.Count - 2]; newFrontScreenStackItem.ScreenController.Focus(); _currentFocussed = newFrontScreenStackItem; } // Close the screen subjectScreenStackItem.ScreenController.Close(); }