GameMgr.cs 5.1 KB

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