StandaloneAPI.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. public class StandaloneAPI
  6. {
  7. public static void ForceBackHome()
  8. {
  9. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  10. if (PersistenHandler.ins)
  11. {
  12. var views = PersistenHandler.ins.menuBackCtr.views;
  13. while (views.Count > 0)
  14. {
  15. var view = views[views.Count - 1];
  16. views.RemoveAt(views.Count - 1);
  17. view.OnMenuBack();
  18. }
  19. }
  20. }
  21. private static Object _GameLocker = new();
  22. public static void PauseGame()
  23. {
  24. string sceneName = SceneManager.GetActiveScene().name;
  25. if (sceneName == "Game" && GameMgr.ins)
  26. {
  27. GameMgr.ins.addLockerForGamePause(_GameLocker);
  28. }
  29. else if (sceneName == "DuckHunter" || sceneName == "WildAttack" || sceneName == "FruitMaster")
  30. {
  31. Time.timeScale = 0;
  32. }
  33. }
  34. public static void ResumeGame()
  35. {
  36. string sceneName = SceneManager.GetActiveScene().name;
  37. if (sceneName == "Game" && GameMgr.ins)
  38. {
  39. GameMgr.ins.removeLockerForGamePause(_GameLocker);
  40. }
  41. else if (sceneName == "DuckHunter" || sceneName == "WildAttack" || sceneName == "FruitMaster")
  42. {
  43. Time.timeScale = 1;
  44. }
  45. }
  46. private static long _GameTimeCountDownMS = 0;
  47. private static void AddGameTimeCountDown(long second)
  48. {
  49. _GameTimeCountDownMS += second * 1000;
  50. }
  51. public static long GetGameTimeCountDown()
  52. {
  53. return _GameTimeCountDownMS;
  54. }
  55. private static long _LastTimeMS;
  56. public static void StartGameTimeCountDown()
  57. {
  58. _LastTimeMS = JCUnityLib.TimeUtils.GetTimestamp();
  59. }
  60. public static void DoGameTimeCountDown()
  61. {
  62. long t = JCUnityLib.TimeUtils.GetTimestamp();
  63. long dt = t - _LastTimeMS;
  64. _LastTimeMS = t;
  65. _GameTimeCountDownMS -= dt;
  66. if (_GameTimeCountDownMS < 0) _GameTimeCountDownMS = 0;
  67. }
  68. private static bool _TimeCounterInited;
  69. public static void InitTimeCounter()
  70. {
  71. if (_TimeCounterInited) return;
  72. _TimeCounterInited = true;
  73. SceneManager.sceneLoaded += (scene, mode) => {
  74. string sceneName = scene.name;
  75. if (sceneName.StartsWith("Game") || sceneName == "DuckHunter" || sceneName == "WildAttack" || sceneName == "FruitMaster")
  76. {
  77. Object.Instantiate(Resources.Load<GameObject>("GameTimeCounterSA"));
  78. }
  79. };
  80. }
  81. /// <summary>
  82. /// 投币加时
  83. /// </summary>
  84. public static void InsertCoinForAddTime()
  85. {
  86. AddGameTimeCountDown(5 * 60);
  87. Debug.Log("UserSettings.ins.PerRoundCoin:" + UserSettings.ins.PerRoundCoin);
  88. Debug.Log("UserSettings.ins.PerRoundSeconds:"+ UserSettings.ins.PerRoundSeconds);
  89. }
  90. }