GameTimeCounterSA.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 (Input.GetKeyDown(KeyCode.Z))
  48. {
  49. //投币接口测试
  50. StandaloneAPI.InsertCoinForAddTime();
  51. }
  52. }
  53. string GetTimeStr()
  54. {
  55. long second = StandaloneAPI.GetGameTimeCountDown() / 1000;
  56. long minute = second / 60;
  57. second = second % 60;
  58. string str = second + "秒";
  59. if (minute > 0) str = minute + "分" + str;
  60. return str;
  61. }
  62. }