public void ExitGame() { SetInterfaces(); popupSettings = new Popup("Do you want to leave the game?", "Exit", "Cancel", "Exit Game"); popup.ShowPopup(PopupManager.Popup.TwoButtons, popupSettings, () => { Debug.Log("[ExampleSingelton] : exit game"); Application.Quit(); }); }
public void Buy() { SetInterfaces(); popupSettings = new Popup("Do you want to buy 15 swords?", "Buy", "Cancel", "Shop"); popup.ShowPopup(PopupManager.Popup.TwoButtons, popupSettings, BuyItem, null); }
public void TimeClose() { SetInterfaces(); popupSettings = new Popup("Popup will close in...", null, null, null, 4); popup.ShowPopup(PopupManager.Popup.TimeInformation, popupSettings); }
private void OneButton(IPopupSettings popupSettings) { btnRight.gameObject.SetActive(true); btnLeft.gameObject.SetActive(false); title.text = popupSettings.Title; information.text = popupSettings.Information; txtRight.text = popupSettings.ButtonRight; }
//######################################################## // popup settings //######################################################## private void TimeInformation(IPopupSettings popupSettings) { btnRight.gameObject.SetActive(false); btnLeft.gameObject.SetActive(false); title.text = popupSettings.Title; StartCoroutine(TimerInformationPopup(popupSettings)); }
//######################################################## // examples of using popups //######################################################## public void LevelUp() { SetInterfaces(); level++; popupSettings = new Popup("You have reached level " + level.ToString(), "OK", null, "Congratulations!"); popup.ShowPopup(PopupManager.Popup.OneButton, popupSettings, null, null); Debug.Log(popupSettings.Information + " " + popupSettings.ButtonLeft.ToString()); }
IEnumerator TimerInformationPopup(IPopupSettings popupSettings) { for (int i = popupSettings.Timer - 1; 0 <= i; i--) { information.text = popupSettings.Information + " " + i; yield return(new WaitForSeconds(1f)); } HidePopup(); }
//######################################################## // interface implementation // IPopup //######################################################## public void ShowPopup(Popup popupType, IPopupSettings popupSettings, Action right = null, Action left = null) { buttonLeft = left; buttonRight = right; popup.SetActive(true); background.SetActive(true); switch (popupType) { case Popup.TimeInformation: TimeInformation(popupSettings); break; case Popup.OneButton: OneButton(popupSettings); break; case Popup.TwoButtons: TwoButtons(popupSettings); break; } }
//######################################################## // popup delegates //######################################################## private void BuyItem() { popupSettings = new Popup("You bought 15 swords.", "OK"); popup.ShowPopup(PopupManager.Popup.OneButton, popupSettings, null, null); }