using System.Collections.Generic; using UnityEngine; /* 游戏管理者(游戏模式:单人模式、PK模式) */ public class GameMgr : MonoBehaviour { public static bool debugInEditor = false; public static int gameType = 0; public GameMode gameMode; [System.NonSerialized] public bool gameOver = false; public static GameMgr ins; void Awake() { ins = this; if (Application.platform == RuntimePlatform.WindowsEditor) { debugInEditor = true; } AudioMgr.Init(); InitGameMode(); DoGameModeStart(); } void OnDestroy() { if (ins == this) ins = null; clearLockerForGamePause(); } void FixedUpdate() { gameMode.Update(); } void Update() { gameMode.FrameUpdate(); } void InitGameMode() { if (gameType == 0) gameMode = new GameModeTest(this); } public void StopGame() { gameOver = true; if (BowCamera.ins) BowCamera.ins.enabled = false; Arrow[] arrows = GameObject.FindObjectsOfType(); foreach(var arrow in arrows) { Destroy(arrow); } } void DoGameModeStart() { gameMode.Start(); } HashSet gamePauseLockers = new HashSet(); public bool gamePause { get { return gamePauseLockers.Count > 0; } } public void addLockerForGamePause(Object o) { gamePauseLockers.Add(o); if (gamePauseLockers.Count > 0) { Time.timeScale = 0; } } public void removeLockerForGamePause(Object o) { gamePauseLockers.Remove(o); if (gamePauseLockers.Count == 0) { Time.timeScale = 1; } } public void clearLockerForGamePause() { gamePauseLockers.Clear(); Time.timeScale = 1; } //现实的计量值转游戏场景的计量值(米) public static float RealSizeToGameSize(float realSize) { // return realSize * 0.413966f; return realSize; } //游戏场景的计量值转现实的计量值(米) public static float GameSizeToRealSize(float gameSize) { // return gameSize / 0.413966f; return gameSize; } }