| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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 = 60 * 1000;
- public RawImage QRimage;
- void Start()
- {
- payMask.SetActive(false);
- StandaloneAPI.StartGameTimeCountDown();
- QRimage.texture = StandaloneAPI.GetQR();
- }
- 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 (Input.GetKeyDown(KeyCode.Z))
- {
- //投币接口测试
- StandaloneAPI.InsertCoinForAddTime();
- }
- }
- 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;
- }
- }
|