GameMgr.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 GameMode gameMode;
  10. [System.NonSerialized] public bool gameOver = false;
  11. public static GameMgr ins;
  12. void Awake()
  13. {
  14. ins = this;
  15. OnlinePKTest.Init();
  16. HomeMgr.HideCacheViews();
  17. if (Application.platform == RuntimePlatform.WindowsEditor)
  18. {
  19. debugInEditor = true;
  20. }
  21. AudioMgr.Init();
  22. this.InitGameMode();
  23. if (debugInEditor) {
  24. guideFinish = true;
  25. DoGameModeStart();
  26. } else {
  27. if (!BluetoothStatus.IsAllConnected()) {
  28. GameObject view = DeviceReconnectView.Show();
  29. if (view) {
  30. view.GetComponent<DeviceReconnectView>().onComplete = CheckGuide;
  31. }
  32. } else {
  33. this.CheckGuide();
  34. }
  35. }
  36. // GameSceneLoadBtns.Create();
  37. Debug.LogWarning("阻止用户游戏统计分析");
  38. // UserGameAnalyse.CreateWhenGameStart(gameType);
  39. }
  40. void Start()
  41. {
  42. try {
  43. GlobalEventCenter.ins.onGameSceneLoad?.Invoke();
  44. } catch (System.Exception e) { Debug.LogError(e.Message); }
  45. if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
  46. }
  47. void OnDestroy() {
  48. try {
  49. GlobalEventCenter.ins.onGameSceneDestroy?.Invoke();
  50. } catch (System.Exception e) { Debug.LogError(e.Message); }
  51. if (AimHandler.ins) AimHandler.ins.Ban9AxisCalculate(false);
  52. clearLockerForGamePause();
  53. if (ins == this) ins = null;
  54. }
  55. void FixedUpdate()
  56. {
  57. gameMode.Update();
  58. }
  59. void Update()
  60. {
  61. gameMode.FrameUpdate();
  62. }
  63. void InitGameMode() {
  64. if (gameType == 0) gameMode = new GameModeTest(this);
  65. if (gameType == 1) gameMode = new TimeLimitGameMode(this);
  66. if (gameType == 2) gameMode = new PKGameMode(this);
  67. if (gameType == 3) gameMode = new RabbitHuntGameMode(this);
  68. if (gameType == 4) gameMode = new YejiHuntGameMode(this);
  69. if (gameType == 5) gameMode = new WolfHuntGameMode(this);
  70. if (gameType == 6) gameMode = new RabbitHuntGameMode_LocalPK(this);
  71. if (gameType == 7) gameMode = new YejiHuntGameMode_LocalPK(this);
  72. if (gameType == 8) gameMode = new WolfHuntGameMode_LocalPK(this);
  73. if (gameType == 9) gameMode = new PKGameMode_OnlinePK(this);
  74. if (gameType == 10) gameMode = new RabbitHuntGameMode_OnlinePK(this);
  75. if (gameType == 11) gameMode = new YejiHuntGameMode_OnlinePK(this);
  76. if (gameType == 12) gameMode = new WolfHuntGameMode_OnlinePK(this);
  77. }
  78. public void StopGame() {
  79. gameOver = true;
  80. if (BowCamera.ins) BowCamera.ins.enabled = false;
  81. Arrow[] arrows = GameObject.FindObjectsOfType<Arrow>();
  82. foreach(var arrow in arrows)
  83. {
  84. Destroy(arrow);
  85. }
  86. }
  87. bool guideFinish = false;
  88. public void CheckGuide() {
  89. if (gameType > 0) {
  90. if (!UserSettings.ins.deviceCalibrateGuideFinish) {
  91. DeviceCalibrateView.Create();
  92. return;
  93. }
  94. if (gameType < 3) {
  95. if (!UserSettings.ins.gameRuleGuideFinish.Contains(gameType)) {
  96. GameRuleView.Create();
  97. return;
  98. }
  99. }
  100. }
  101. guideFinish = true;
  102. DoGameModeStart();
  103. }
  104. public void FinishGameRuleGuide() {
  105. if (guideFinish) return;
  106. UserSettings.ins.gameRuleGuideFinish.Add(gameType);
  107. UserSettings.ins.Save();
  108. CheckGuide();
  109. }
  110. public void FinishDeviceCalibrateGuide() {
  111. if (guideFinish) return;
  112. UserSettings.ins.deviceCalibrateGuideFinish = true;
  113. UserSettings.ins.Save();
  114. CheckGuide();
  115. }
  116. void DoGameModeStart() {
  117. gameMode.Start();
  118. }
  119. HashSet<Object> gamePauseLockers = new HashSet<Object>();
  120. public bool gamePause {
  121. get {
  122. return gamePauseLockers.Count > 0;
  123. }
  124. }
  125. public void addLockerForGamePause(Object o)
  126. {
  127. gamePauseLockers.Add(o);
  128. if (gamePauseLockers.Count > 0) {
  129. Time.timeScale = 0;
  130. }
  131. }
  132. public void removeLockerForGamePause(Object o)
  133. {
  134. gamePauseLockers.Remove(o);
  135. if (gamePauseLockers.Count == 0) {
  136. Time.timeScale = 1;
  137. }
  138. }
  139. public void clearLockerForGamePause()
  140. {
  141. gamePauseLockers.Clear();
  142. Time.timeScale = 1;
  143. }
  144. //现实的计量值转游戏场景的计量值(米)
  145. public static float RealSizeToGameSize(float realSize)
  146. {
  147. // return realSize * 0.413966f;
  148. return realSize;
  149. }
  150. //游戏场景的计量值转现实的计量值(米)
  151. public static float GameSizeToRealSize(float gameSize)
  152. {
  153. // return gameSize / 0.413966f;
  154. return gameSize;
  155. }
  156. }