private void Update() { string displayString = ""; // arbitrary end date, will modify when months become objects, not just prefabs if (this.totalScore < 0 || this.gameManager.GetDaysPassed() >= 26) { // game is over, complete game-over string with score and days passed displayString = "Days Lasted: " + (this.gameManager.GetDaysPassed() + 1).ToString() + " " + "Money Made: " + this.totalScore.ToString(); this.modalState = ModalUI.ModalState.GameOver; } // if the modal is intended to be in a state where it is displayed, display it. Otherwise hide it. if (modalState != ModalUI.ModalState.HideModal && modalState != ModalUI.ModalState.NoState) { SpawnModal(this.modalState, displayString); AdjustModalPositionScale(); BlockInput(true); } else if (modal.activeSelf && modalState == ModalUI.ModalState.HideModal) { HideModal(); BlockInput(false); } }
private void DisplayModal(ModalUI.ModalState state, string displayString) { if (modal == null) { modal = Instantiate(this.modalPrefab, this.backgroundCanvas.transform, false); modal.transform.SetAsLastSibling(); } modal.SetActive(true); ModalEvent(state, displayString); }
public static CameraNotification BlockInput; // used to block user input on all areas of screen except for the modal when spawned private void Awake() { this.gameManager = GameManager.GetInstance(); this.monthBuilder = MonthBuilder.GetInstance(); // spawn the modal but hide it. The modal base size is the size of the entire calendar this.modal = Instantiate(this.modalPrefab, this.gameObject.transform, false); this.modalState = ModalUI.ModalState.NoState; this.modal.SetActive(false); ModalUI.NotifyCaller += ModalCloseEvent; DayUI.NotifyCalendarSelectDay += DaySelected; MonthUI.NotifyCurrentDay += SetCurrentDayTransform; }
private void HandleModalEvent(ModalUI.ModalState modalState) { switch (modalState) { case ModalUI.ModalState.EndDay: SetAndLoadNewState(States.CalendarScene); break; case ModalUI.ModalState.DaySelect: SetAndLoadNewState(States.GameplayScene); break; case ModalUI.ModalState.GameOver: DeleteOldGame(); SetAndLoadNewState(States.TitleScene); break; } }
/**** Events ****/ private void SetupStartGame(ModalUI.ModalState state) { // destroy modal HideModal(); StartGame(); }
// called when a day is selected, update the modal state to allow display of modal // centered on the day private void DaySelected() { this.modalState = ModalUI.ModalState.DaySelect; }
// notifies the calendar that the modal should be hidden private void ModalCloseEvent(ModalUI.ModalState currentModalState) { this.modalState = ModalUI.ModalState.HideModal; }
// hides the modal to allow interaction with the calendar private void HideModal() { this.modalState = ModalUI.ModalState.NoState; this.modal.SetActive(false); }
// spawn a modal that will allow an action based on the modal state private void SpawnModal(ModalUI.ModalState state, string displayString) { this.modal.transform.SetAsLastSibling(); this.modal.SetActive(true); ModalNotification(state, displayString); }