| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class GameTimeCounterSA : MonoBehaviour
- {
- [SerializeField] Text playTimeText;
- [SerializeField] Text cointCountText;
- [SerializeField] GameObject payMask;
- [SerializeField] Text payTimeCountDownText;
- bool _paused;
- long _pauseTimePoint;
- const long PayTimeCountDown = 60 * 1000;
- public RawImage QRimage;
- string coinContinueGameUnit;
- string remainingTimeUnit;
- string minutesUnit;
- string secondsUnit;
- string coinsUnit;
- void Start()
- {
- payMask.SetActive(false);
- coinContinueGameUnit = TextAutoLanguage2.GetTextByKey("CoinContinueGame");
- remainingTimeUnit = TextAutoLanguage2.GetTextByKey("RemainingTime");
- minutesUnit = TextAutoLanguage2.GetTextByKey("Minutes");
- secondsUnit = TextAutoLanguage2.GetTextByKey("Seconds");
- coinsUnit = TextAutoLanguage2.GetTextByKey("CoinsInfo");
- StandaloneAPI.StartGameTimeCountDown();
- QRimage.texture = StandaloneAPI.GetQR();
- }
- void Update()
- {
- //游戏投币测试
- if (Input.GetKeyDown(KeyCode.Alpha7))
- {
- //投币接口测试
- StandaloneAPI.InsertCoint(7);
- }
- StandaloneAPI.DoGameTimeCountDown();
- //"剩余时间{0}"
- playTimeText.text = string.Format(remainingTimeUnit, 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;
- //"投币继续游戏\n{0}S"
- payTimeCountDownText.text = string.Format(coinContinueGameUnit, t / 1000);
- if (UserSettings.ins != null)
- {
- //"币:{0}/{1}"
- cointCountText.text = string.Format(coinsUnit, StandaloneAPI.CoinCount, UserSettings.ins.PerRoundCoin);
- }
- if (t == 0) StandaloneAPI.ForceBackHome();
- }
- //#if UNITY_EDITOR
- //#endif
- }
- string GetTimeStr()
- {
- long second = StandaloneAPI.GetGameTimeCountDown() / 1000;
- long minute = second / 60;
- second = second % 60;
- string str = second + secondsUnit;//"秒";
- if (minute > 0) str = minute + minutesUnit + str; //"分"
- return str;
- }
- }
|