| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using System.Collections;
- 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;
- OnlinePKTest.Init();
- HomeMgr.HideCacheViews();
- if (Application.platform == RuntimePlatform.WindowsEditor)
- {
- debugInEditor = true;
- }
- AudioMgr.Init();
- this.InitGameMode();
- if (debugInEditor) {
- guideFinish = true;
- DoGameModeStart();
- } else {
- if (!BluetoothStatus.IsAllConnected()) {
- GameObject view = DeviceReconnectView.Show();
- if (view) {
- view.GetComponent<DeviceReconnectView>().onComplete = CheckGuide;
- }
- } else {
- this.CheckGuide();
- }
- }
- // GameSceneLoadBtns.Create();
- Debug.LogWarning("阻止用户游戏统计分析");
- // UserGameAnalyse.CreateWhenGameStart(gameType);
- }
- void Start()
- {
- try {
- GlobalEventCenter.ins.onGameSceneLoad?.Invoke();
- } catch (System.Exception e) { Debug.LogError(e.Message); }
- if (ShootCheck.ins) ShootCheck.ins.AdjustNormalOrHightMode();
- }
- void OnDestroy() {
- try {
- GlobalEventCenter.ins.onGameSceneDestroy?.Invoke();
- } catch (System.Exception e) { Debug.LogError(e.Message); }
- if (AimHandler.ins) AimHandler.ins.Ban9AxisCalculate(false);
- clearLockerForGamePause();
- if (ins == this) ins = null;
- }
- void FixedUpdate()
- {
- gameMode.Update();
- }
- void Update()
- {
- gameMode.FrameUpdate();
- }
- void InitGameMode() {
- if (gameType == 0) gameMode = new GameModeTest(this);
- if (gameType == 1) gameMode = new TimeLimitGameMode(this);
- if (gameType == 2) gameMode = new PKGameMode(this);
- if (gameType == 3) gameMode = new RabbitHuntGameMode(this);
- if (gameType == 4) gameMode = new YejiHuntGameMode(this);
- if (gameType == 5) gameMode = new WolfHuntGameMode(this);
- if (gameType == 6) gameMode = new RabbitHuntGameMode_LocalPK(this);
- if (gameType == 7) gameMode = new YejiHuntGameMode_LocalPK(this);
- if (gameType == 8) gameMode = new WolfHuntGameMode_LocalPK(this);
- if (gameType == 9) gameMode = new PKGameMode_OnlinePK(this);
- if (gameType == 10) gameMode = new RabbitHuntGameMode_OnlinePK(this);
- if (gameType == 11) gameMode = new YejiHuntGameMode_OnlinePK(this);
- if (gameType == 12) gameMode = new WolfHuntGameMode_OnlinePK(this);
- }
- public void StopGame() {
- gameOver = true;
- if (BowCamera.ins) BowCamera.ins.enabled = false;
- Arrow[] arrows = GameObject.FindObjectsOfType<Arrow>();
- foreach(var arrow in arrows)
- {
- Destroy(arrow);
- }
- }
- bool guideFinish = false;
- public void CheckGuide() {
- if (gameType > 0) {
- if (!UserSettings.ins.deviceCalibrateGuideFinish) {
- DeviceCalibrateView.Create();
- return;
- }
- if (gameType < 3) {
- if (!UserSettings.ins.gameRuleGuideFinish.Contains(gameType)) {
- GameRuleView.Create();
- return;
- }
- }
- }
- guideFinish = true;
- DoGameModeStart();
- }
- public void FinishGameRuleGuide() {
- if (guideFinish) return;
- UserSettings.ins.gameRuleGuideFinish.Add(gameType);
- UserSettings.ins.Save();
- CheckGuide();
- }
-
- public void FinishDeviceCalibrateGuide() {
- if (guideFinish) return;
- UserSettings.ins.deviceCalibrateGuideFinish = true;
- UserSettings.ins.Save();
- CheckGuide();
- }
- void DoGameModeStart() {
- gameMode.Start();
- }
- HashSet<Object> gamePauseLockers = new HashSet<Object>();
- 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;
- }
- }
|