GameTimeCounterSA.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. //投币测试
  23. if (Input.GetKeyDown(KeyCode.Alpha7) || Input.GetKeyDown(KeyCode.Alpha8))
  24. {
  25. //投币接口测试
  26. StandaloneAPI.InsertCoinForAddTime();
  27. }
  28. StandaloneAPI.DoGameTimeCountDown();
  29. playTimeText.text = string.Format("剩余时间{0}", GetTimeStr());
  30. if (StandaloneAPI.GetGameTimeCountDown() > 0)
  31. {
  32. if (_paused)
  33. {
  34. payMask.SetActive(false);
  35. StandaloneAPI.ResumeGame();
  36. _paused = false;
  37. }
  38. }
  39. else
  40. {
  41. if (!_paused)
  42. {
  43. payMask.SetActive(true);
  44. StandaloneAPI.PauseGame();
  45. _paused = true;
  46. _pauseTimePoint = JCUnityLib.TimeUtils.GetTimestamp();
  47. }
  48. long t = PayTimeCountDown - (JCUnityLib.TimeUtils.GetTimestamp() - _pauseTimePoint);
  49. if (t <= 0) t = 0;
  50. payTimeCountDownText.text = string.Format("投币继续游戏\n{0}S", t / 1000);
  51. if (t == 0) StandaloneAPI.ForceBackHome();
  52. }
  53. //#if UNITY_EDITOR
  54. //#endif
  55. }
  56. string GetTimeStr()
  57. {
  58. long second = StandaloneAPI.GetGameTimeCountDown() / 1000;
  59. long minute = second / 60;
  60. second = second % 60;
  61. string str = second + "秒";
  62. if (minute > 0) str = minute + "分" + str;
  63. return str;
  64. }
  65. }