private void Start() { parentScreen = GetComponentInParent <Screen>(); Assert.IsNotNull(parentScreen); // No assertion for button component is needed as this is already enforced through RequireComponent buttonComponent = GetComponent <Button>(); buttonComponent.onClick.AddListener(DoClick); }
/// <summary> /// Transition to the provided screen. /// </summary> /// <param name="screen">Screen to transition to.</param> /// <param name="saveToHistory">Indicates if this transition should be save to the screen history.</param> public void TransitionToScreen(Screen screen, bool saveToHistory = true) { if (!screens.Contains(screen)) { throw new InvalidOperationException( $"Tried to transition to screen {screen.Name}, but this screen is not registered to this uiManager ({this})" ); } SetActiveScreen(screen, saveToHistory); }
private void SetActiveScreen(Screen screen, bool saveToHistory = true) { if (activeScreen != null) { if (saveToHistory) { screenHistory.Push(activeScreen); } activeScreen.Active = false; } activeScreen = screen; activeScreen.Active = true; }
private Button CreateScreenButton(Screen screen) { var button = new Button { text = screen.Name == string.Empty ? "<unnamed>" : screen.Name }; button.clickable.clicked += () => { // Don't use the Active property of the screen object for editing, because it's meant to be used in // play mode. Using it outside play mode will result in NullRef errors. Set the active property of the // gameObject directly instead. uiManager.GetScreens().ForEach(s => s.gameObject.SetActive(false)); screen.gameObject.SetActive(true); }; return(button); }