| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class StandaloneAPI
- {
- public static void ForceBackHome()
- {
- SceneManager.LoadScene("Home", LoadSceneMode.Single);
- if (PersistenHandler.ins)
- {
- var views = PersistenHandler.ins.menuBackCtr.views;
- while (views.Count > 0)
- {
- var view = views[views.Count - 1];
- views.RemoveAt(views.Count - 1);
- view.OnMenuBack();
- }
- }
- }
- private static Object _GameLocker = new();
- public static void PauseGame()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName == "Game" && GameMgr.ins)
- {
- GameMgr.ins.addLockerForGamePause(_GameLocker);
- }
- else if (sceneName == "DuckHunter" || sceneName == "WildAttack" || sceneName == "FruitMaster")
- {
- Time.timeScale = 0;
- }
- }
- public static void ResumeGame()
- {
- string sceneName = SceneManager.GetActiveScene().name;
- if (sceneName == "Game" && GameMgr.ins)
- {
- GameMgr.ins.removeLockerForGamePause(_GameLocker);
- }
- else if (sceneName == "DuckHunter" || sceneName == "WildAttack" || sceneName == "FruitMaster")
- {
- Time.timeScale = 1;
- }
- }
- private static long _GameTimeCountDownMS = 0;
- private static void AddGameTimeCountDown(long second)
- {
- _GameTimeCountDownMS += second * 1000;
- }
- public static long GetGameTimeCountDown()
- {
- return _GameTimeCountDownMS;
- }
- private static long _LastTimeMS;
- public static void StartGameTimeCountDown()
- {
- _LastTimeMS = JCUnityLib.TimeUtils.GetTimestamp();
- }
- public static void DoGameTimeCountDown()
- {
- long t = JCUnityLib.TimeUtils.GetTimestamp();
- long dt = t - _LastTimeMS;
- _LastTimeMS = t;
- _GameTimeCountDownMS -= dt;
- if (_GameTimeCountDownMS < 0) _GameTimeCountDownMS = 0;
- }
- private static bool _TimeCounterInited;
- public static void InitTimeCounter()
- {
- if (_TimeCounterInited) return;
- _TimeCounterInited = true;
- SceneManager.sceneLoaded += (scene, mode) => {
- string sceneName = scene.name;
- if (sceneName.StartsWith("Game") || sceneName == "DuckHunter" || sceneName == "WildAttack" || sceneName == "FruitMaster")
- {
- //操作引导场景不用投币
- if (!GameMgr.bShowDistance && GameMgr.turnOffTimer) return;
- Object.Instantiate(Resources.Load<GameObject>("GameTimeCounterSA"));
- }
- };
- }
- /// <summary>
- /// 投币加时
- /// </summary>
- public static void InsertCoinForAddTime()
- {
- AddGameTimeCountDown(5 * 60);
- Debug.Log("UserSettings.ins.PerRoundCoin:" + UserSettings.ins.PerRoundCoin);
- Debug.Log("UserSettings.ins.PerRoundSeconds:"+ UserSettings.ins.PerRoundSeconds);
- }
- }
|