GameMgr.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. /* 游戏管理者(游戏模式:单人模式、PK模式) */
  4. public class GameMgr : MonoBehaviour
  5. {
  6. public static bool debugInEditor = false;
  7. public static int gameType = 0;
  8. public GameMode gameMode;
  9. [System.NonSerialized] public bool gameOver = false;
  10. public static GameMgr ins;
  11. void Awake()
  12. {
  13. ins = this;
  14. if (Application.platform == RuntimePlatform.WindowsEditor)
  15. {
  16. debugInEditor = true;
  17. }
  18. AudioMgr.Init();
  19. InitGameMode();
  20. DoGameModeStart();
  21. }
  22. void OnDestroy() {
  23. if (ins == this) ins = null;
  24. clearLockerForGamePause();
  25. }
  26. void FixedUpdate()
  27. {
  28. gameMode.Update();
  29. }
  30. void Update()
  31. {
  32. gameMode.FrameUpdate();
  33. }
  34. void InitGameMode() {
  35. if (gameType == 0) gameMode = new GameModeTest(this);
  36. }
  37. public void StopGame() {
  38. gameOver = true;
  39. if (BowCamera.ins) BowCamera.ins.enabled = false;
  40. Arrow[] arrows = GameObject.FindObjectsOfType<Arrow>();
  41. foreach(var arrow in arrows)
  42. {
  43. Destroy(arrow);
  44. }
  45. }
  46. void DoGameModeStart() {
  47. gameMode.Start();
  48. }
  49. HashSet<Object> gamePauseLockers = new HashSet<Object>();
  50. public bool gamePause {
  51. get {
  52. return gamePauseLockers.Count > 0;
  53. }
  54. }
  55. public void addLockerForGamePause(Object o)
  56. {
  57. gamePauseLockers.Add(o);
  58. if (gamePauseLockers.Count > 0) {
  59. Time.timeScale = 0;
  60. }
  61. }
  62. public void removeLockerForGamePause(Object o)
  63. {
  64. gamePauseLockers.Remove(o);
  65. if (gamePauseLockers.Count == 0) {
  66. Time.timeScale = 1;
  67. }
  68. }
  69. public void clearLockerForGamePause()
  70. {
  71. gamePauseLockers.Clear();
  72. Time.timeScale = 1;
  73. }
  74. //现实的计量值转游戏场景的计量值(米)
  75. public static float RealSizeToGameSize(float realSize)
  76. {
  77. // return realSize * 0.413966f;
  78. return realSize;
  79. }
  80. //游戏场景的计量值转现实的计量值(米)
  81. public static float GameSizeToRealSize(float gameSize)
  82. {
  83. // return gameSize / 0.413966f;
  84. return gameSize;
  85. }
  86. }