| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- 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 static bool turnOffTimer = false;
- public static int judgmentGameType = 0;
- public GameMode gameMode;
- [System.NonSerialized] public bool gameOver = false;
- public static GameMgr ins;
- public UserGameAnalyse userGameAnalyse;
- public static bool bNavBack = false;
- public static bool bShowDistance = true;
- //隐藏左边的靶子和底部速度牌
- public static bool HideTargetView { get; set; } = false;
- public static bool HideBillboard { get; set; } = false;
- public static int ButtonCount { get; set; } = 0;
- void Awake()
- {
- ins = this;
- // try { //隐藏了手臂和弓,且拉弓搭箭速度提高10倍
- // transform.Find("Main Camera").GetComponent<Camera>().cullingMask = -1033;
- // transform.Find("Main Camera/ArmBow").GetComponent<AnimationPlayer>().speed = 20;
- // } catch (System.Exception) {}
- OnlinePKTest.Init();
- if (Application.platform == RuntimePlatform.WindowsEditor)
- {
- debugInEditor = false;
- }
- AudioMgr.Init();
- this.InitGameMode();
- if (debugInEditor) {
- guideFinish = true;
- DoGameModeStart();
- } else {
- CheckGuide();
- }
- userGameAnalyse = UserGameAnalyse.CreateWhenGameStartAndReturn(gameType);
- }
- void Start()
- {
- try {
- GlobalEventCenter.ins.onGameSceneLoad?.Invoke();
- } catch (System.Exception e) { Debug.LogError(e.Message); }
- //if (ShootCheck.ins) {
- // ShootCheck.ins.AdjustNormalOrHightMode();
- //}
- }
- void OnDestroy() {
- //此脚本删除后重新设置 bShowDistance bNavBack turnOffTimer
- bShowDistance = true;
- bNavBack = false;
- turnOffTimer = false;
- try
- {
- GlobalEventCenter.ins.onGameSceneDestroy?.Invoke();
- } catch (System.Exception e) { Debug.LogError(e.Message); }
- if (AimHandler.ins) {
- AimHandler.ins.Ban9AxisCalculate(false);
- AimHandler.ins.bInitOne = 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 (bShowDistance) {
- if (gameType > 0)
- {
- if (!UserSettings.ins.deviceCalibrateGuideFinish) //&& !InfraredDemo.running
- {
- 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();
- SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
- }
- 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;
- }
- }
|