| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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")
- {
- 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);
- }
- }
|