GameMgr.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using AppUI.Bluetooth;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /* 游戏管理者(游戏模式:单人模式、PK模式) */
  6. public class GameMgr : MonoBehaviour
  7. {
  8. public static bool debugInEditor = false;
  9. public static int gameType = 0;
  10. public static bool turnOffTimer = false;
  11. public static int judgmentGameType = 0;
  12. public GameMode gameMode;
  13. [System.NonSerialized] public bool gameOver = false;
  14. public static GameMgr ins;
  15. public UserGameAnalyse userGameAnalyse;
  16. public static bool bNavBack = false;
  17. public static bool bShowDistance = true;
  18. //隐藏左边的靶子和底部速度牌
  19. public static bool HideTargetView { get; set; } = false;
  20. public static bool HideBillboard { get; set; } = false;
  21. public static int ButtonCount { get; set; } = 0;
  22. void Awake()
  23. {
  24. ins = this;
  25. // try { //隐藏了手臂和弓,且拉弓搭箭速度提高10倍
  26. // transform.Find("Main Camera").GetComponent<Camera>().cullingMask = -1033;
  27. // transform.Find("Main Camera/ArmBow").GetComponent<AnimationPlayer>().speed = 20;
  28. // } catch (System.Exception) {}
  29. OnlinePKTest.Init();
  30. if (Application.platform == RuntimePlatform.WindowsEditor)
  31. {
  32. debugInEditor = false;
  33. }
  34. AudioMgr.Init();
  35. this.InitGameMode();
  36. if (debugInEditor) {
  37. guideFinish = true;
  38. DoGameModeStart();
  39. } else {
  40. CheckGuide();
  41. }
  42. userGameAnalyse = UserGameAnalyse.CreateWhenGameStartAndReturn(gameType);
  43. }
  44. void Start()
  45. {
  46. try {
  47. GlobalEventCenter.ins.onGameSceneLoad?.Invoke();
  48. } catch (System.Exception e) { Debug.LogError(e.Message); }
  49. //if (ShootCheck.ins) {
  50. // ShootCheck.ins.AdjustNormalOrHightMode();
  51. //}
  52. }
  53. void OnDestroy() {
  54. //此脚本删除后重新设置 bShowDistance bNavBack turnOffTimer
  55. bShowDistance = true;
  56. bNavBack = false;
  57. turnOffTimer = false;
  58. try
  59. {
  60. GlobalEventCenter.ins.onGameSceneDestroy?.Invoke();
  61. } catch (System.Exception e) { Debug.LogError(e.Message); }
  62. if (SmartBowDeviceHub.ins?.Aim) {
  63. //SmartBowDeviceHub.ins.Aim.Ban9AxisCalculate(false);
  64. SmartBowDeviceHub.ins.Aim.bInitOne = false;
  65. }
  66. clearLockerForGamePause();
  67. if (ins == this) ins = null;
  68. }
  69. void FixedUpdate()
  70. {
  71. gameMode.Update();
  72. }
  73. void Update()
  74. {
  75. gameMode.FrameUpdate();
  76. }
  77. void InitGameMode() {
  78. if (gameType == 0) gameMode = new GameModeTest(this);
  79. if (gameType == 1) gameMode = new TimeLimitGameMode(this);
  80. if (gameType == 2) gameMode = new PKGameMode(this);
  81. if (gameType == 3) gameMode = new RabbitHuntGameMode(this);
  82. if (gameType == 4) gameMode = new YejiHuntGameMode(this);
  83. if (gameType == 5) gameMode = new WolfHuntGameMode(this);
  84. if (gameType == 6) gameMode = new RabbitHuntGameMode_LocalPK(this);
  85. if (gameType == 7) gameMode = new YejiHuntGameMode_LocalPK(this);
  86. if (gameType == 8) gameMode = new WolfHuntGameMode_LocalPK(this);
  87. if (gameType == 9) gameMode = new PKGameMode_OnlinePK(this);
  88. if (gameType == 10) gameMode = new RabbitHuntGameMode_OnlinePK(this);
  89. if (gameType == 11) gameMode = new YejiHuntGameMode_OnlinePK(this);
  90. if (gameType == 12) gameMode = new WolfHuntGameMode_OnlinePK(this);
  91. }
  92. public void StopGame() {
  93. gameOver = true;
  94. if (BowCamera.ins) BowCamera.ins.enabled = false;
  95. Arrow[] arrows = GameObject.FindObjectsOfType<Arrow>();
  96. foreach(var arrow in arrows)
  97. {
  98. Destroy(arrow);
  99. }
  100. }
  101. bool guideFinish = false;
  102. public void CheckGuide() {
  103. //地磁计跳进来不需要初始化任务
  104. if (bShowDistance) {
  105. if (gameType > 0)
  106. {
  107. //if (!UserSettings.ins.deviceCalibrateGuideFinish) //&& !InfraredDemo.running
  108. //{
  109. // //DeviceCalibrateView.Create();
  110. // return;
  111. //}
  112. if (gameType < 3)
  113. {
  114. if (!UserSettings.ins.gameRuleGuideFinish.Contains(gameType))
  115. {
  116. GameRuleView.Create();
  117. return;
  118. }
  119. }
  120. }
  121. }
  122. guideFinish = true;
  123. DoGameModeStart();
  124. }
  125. public void FinishGameRuleGuide() {
  126. if (guideFinish) return;
  127. UserSettings.ins.gameRuleGuideFinish.Add(gameType);
  128. UserSettings.ins.Save();
  129. CheckGuide();
  130. }
  131. public void FinishDeviceCalibrateGuide() {
  132. if (guideFinish) return;
  133. UserSettings.ins.deviceCalibrateGuideFinish = true;
  134. UserSettings.ins.Save();
  135. CheckGuide();
  136. }
  137. void DoGameModeStart() {
  138. gameMode.Start();
  139. SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
  140. }
  141. HashSet<Object> gamePauseLockers = new HashSet<Object>();
  142. public bool gamePause {
  143. get {
  144. return gamePauseLockers.Count > 0;
  145. }
  146. }
  147. public void addLockerForGamePause(Object o)
  148. {
  149. gamePauseLockers.Add(o);
  150. if (gamePauseLockers.Count > 0) {
  151. Time.timeScale = 0;
  152. }
  153. }
  154. public void removeLockerForGamePause(Object o)
  155. {
  156. gamePauseLockers.Remove(o);
  157. if (gamePauseLockers.Count == 0) {
  158. Time.timeScale = 1;
  159. }
  160. }
  161. public void clearLockerForGamePause()
  162. {
  163. gamePauseLockers.Clear();
  164. Time.timeScale = 1;
  165. }
  166. //现实的计量值转游戏场景的计量值(米)
  167. public static float RealSizeToGameSize(float realSize)
  168. {
  169. // return realSize * 0.413966f;
  170. return realSize;
  171. }
  172. //游戏场景的计量值转现实的计量值(米)
  173. public static float GameSizeToRealSize(float gameSize)
  174. {
  175. // return gameSize / 0.413966f;
  176. return gameSize;
  177. }
  178. }