GameMgr.cs 6.0 KB

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