public int waitSeconds = 3 * 60; // Interval for free gift: 3 minutes. void OnGUI() { if (textStyle == null) { SetUpStyles(); } GUILayout.BeginHorizontal(GUI.skin.label, GUILayout.Width(Screen.width)); GUILayout.Label("FreeGift:", textStyle); // Main routine: Control Free Gift. if (FreeGiftTimer.IsValid()) { if (FreeGiftTimer.CanSend()) { // Can get a free gift. if (GUILayout.Button("Get", buttonStyle)) { FreeGiftTimer.SetNextWait(waitSeconds); } } else { // Cannot get a free gift because the time has not yet come. GUILayout.Label("Next: " + FreeGiftTimer.GetRemainingTime() + " sec later", textStyle); } } else { // Cannot get a free gift because the clock is invalid. GUILayout.Label("Unavailable", textStyle); } GUILayout.EndHorizontal(); }
void Update() { if (isCollectingGift == true) { if (newAmount != previousStars + rewardAmount) { IncreaseCounter(1); } else if (isCollectingGift == true) { isCollectingGift = false; StartCoroutine(fade()); } } var newTimerState = GetTimerState(); if (newTimerState != timerState) { timerState = newTimerState; ChangeScreen(); } switch (timerState) { case TimerState.WAITING: if (isCollectingGift == false) { var sec = FreeGiftTimer.GetRemainingTime(); hours = FreeGiftTimer.GetRemainingTime() / 3600; mins = (FreeGiftTimer.GetRemainingTime() % 3600) / 60; secs = (FreeGiftTimer.GetRemainingTime() % 3600) % 60; //Debug.Log (hours); //Debug.Log (mins); //Debug.Log (secs); //FreeGiftTimer.SetNextWait(0); waitingText.text = string.Format("{0:00}:{1:00}:{2:00}", hours, mins, secs); // waitingText.text = string.Format ("{0} sec", sec); } break; } }
public void OnGetButtonPressed() { FreeGiftTimer.SetNextWait(waitSeconds); // Hide all UIs. invalidNode.SetActive(false); waitingNode.SetActive(false); canSendNode.SetActive(false); gameObject.SetActive(false); // Pause self action until coin demo will be finished. //var coin = FREE_GIFT_COIN_TABLE[Random.Range(0, FREE_GIFT_COIN_TABLE.Length)]; gameObject.SetActive(true); // Resume. CollectStars(); }
private TimerState GetTimerState() { if (FreeGiftTimer.IsValid()) { if (FreeGiftTimer.CanSend()) { return(TimerState.CAN_SEND); } else { return(TimerState.WAITING); } } else { return(TimerState.INVALID); } }
static OnGuiSampleController() { // Advanced topic: // Set custom save/restore delegates (default: use PlayerPrefs). string KEY_FREE_GIFT = "freeGift"; FreeGiftTimer.SetSaveRestoreDelegate( // Save delegate (long value) => { // Replace to your custom save method. PlayerPrefs.SetString(KEY_FREE_GIFT, value.ToString()); }, // Restore delegate () => { // Replace to your custom restore method. var value = PlayerPrefs.GetString(KEY_FREE_GIFT); try { return(long.Parse(value)); } catch (System.Exception) { // Return 0 when restore is failed. return(0); } }); }