using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class GameTimeCounterSA : MonoBehaviour { [SerializeField] Text playTimeText; [SerializeField] GameObject payMask; [SerializeField] Text payTimeCountDownText; bool _paused; long _pauseTimePoint; const long PayTimeCountDown = 60 * 1000; private GameObject serialPortObj; void Start() { //防止遮挡 string sceneName = SceneManager.GetActiveScene().name; if (sceneName == "DuckHunter") { playTimeText.rectTransform.anchoredPosition = new Vector2(0, 140); } StandaloneAPI.StartGameTimeCountDown(); serialPortObj = GameObject.Find("SerialPortObj"); string qrUrl = serialPortObj.GetComponent().getQRCodeUrl(); if (!string.IsNullOrEmpty(qrUrl)) { GetComponent().onlyQRCode(qrUrl, 512, 512); } Debug.Log("GameTimeCounterSA sceneName:" + sceneName); } 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}", t / 1000); if (t == 0) { StandaloneAPI.ForceBackHome(); serialPortObj.GetComponent().setQRPlanObjActive(true); } } #if UNITY_EDITOR if (Input.GetKeyDown(KeyCode.Z)) { //投币接口测试 StandaloneAPI.InsertCoinForAddTime(); } #endif } 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; } }