GameTimeCounterSA.cs 2.2 KB

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