GameTimeCounterSA.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class GameTimeCounterSA : MonoBehaviour
  6. {
  7. [SerializeField] Text playTimeText;
  8. [SerializeField] GameObject payMask;
  9. [SerializeField] Text payTimeCountDownText;
  10. bool _paused;
  11. long _pauseTimePoint;
  12. const long PayTimeCountDown = 60 * 1000;
  13. public RawImage QRimage;
  14. void Start()
  15. {
  16. payMask.SetActive(false);
  17. StandaloneAPI.StartGameTimeCountDown();
  18. QRimage.texture = StandaloneAPI.GetQR();
  19. }
  20. void Update()
  21. {
  22. StandaloneAPI.DoGameTimeCountDown();
  23. playTimeText.text = string.Format("剩余时间{0}", GetTimeStr());
  24. if (StandaloneAPI.GetGameTimeCountDown() > 0)
  25. {
  26. if (_paused)
  27. {
  28. payMask.SetActive(false);
  29. StandaloneAPI.ResumeGame();
  30. _paused = false;
  31. }
  32. }
  33. else
  34. {
  35. if (!_paused)
  36. {
  37. payMask.SetActive(true);
  38. StandaloneAPI.PauseGame();
  39. _paused = true;
  40. _pauseTimePoint = JCUnityLib.TimeUtils.GetTimestamp();
  41. }
  42. long t = PayTimeCountDown - (JCUnityLib.TimeUtils.GetTimestamp() - _pauseTimePoint);
  43. if (t <= 0) t = 0;
  44. payTimeCountDownText.text = string.Format("投币继续游戏\n{0}S", t / 1000);
  45. if (t == 0) StandaloneAPI.ForceBackHome();
  46. }
  47. #if UNITY_EDITOR
  48. if (Input.GetKeyDown(KeyCode.Z))
  49. {
  50. //投币接口测试
  51. StandaloneAPI.InsertCoinForAddTime();
  52. }
  53. #endif
  54. }
  55. string GetTimeStr()
  56. {
  57. long second = StandaloneAPI.GetGameTimeCountDown() / 1000;
  58. long minute = second / 60;
  59. second = second % 60;
  60. string str = second + "秒";
  61. if (minute > 0) str = minute + "分" + str;
  62. return str;
  63. }
  64. }