| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class GameTimeCounterSA : MonoBehaviour
- {
- [SerializeField] Text playTimeText;
- [SerializeField] GameObject payMask;
- [SerializeField] Text payTimeCountDownText;
- bool _paused;
- long _pauseTimePoint;
- const long PayTimeCountDown = 10 * 1000;
- void Start()
- {
- StandaloneAPI.StartGameTimeCountDown();
- }
- void Update()
- {
- StandaloneAPI.DoGameTimeCountDown();
- playTimeText.text = string.Format("剩余时间{0}", GetTimeStr());
- if (StandaloneAPI.GetGameTimeCountDown() > 0)
- {
- if (_paused)
- {
- payMask.SetActive(false);
- StandaloneAPI.ResumeGame();
- _paused = false;
- }
- }
- else
- {
- if (!_paused)
- {
- payMask.SetActive(true);
- StandaloneAPI.PauseGame();
- _paused = true;
- _pauseTimePoint = JCUnityLib.TimeUtils.GetTimestamp();
- }
- long t = PayTimeCountDown - (JCUnityLib.TimeUtils.GetTimestamp() - _pauseTimePoint);
- if (t <= 0) t = 0;
- payTimeCountDownText.text = string.Format("投币继续游戏\n{0}S", t / 1000);
- if (t == 0) StandaloneAPI.ForceBackHome();
- }
- #if UNITY_EDITOR
- if (Input.GetKeyDown(KeyCode.Z))
- {
- //投币接口测试
- StandaloneAPI.InsertCoinForAddTime();
- }
- #endif
- }
- string GetTimeStr()
- {
- long second = StandaloneAPI.GetGameTimeCountDown() / 1000;
- long minute = second / 60;
- second = second % 60;
- string str = second + "秒";
- if (minute > 0) str = minute + "分" + str;
- return str;
- }
- }
|