using UnityEngine; public class GameMgr : MonoBehaviour { public static int gameMode = 1; public GameMode1 gameMode1; public bool gameOver = false; public static GameMgr ins; void Start() { ins = this; AudioMgr.init(); this.initGameMode(); } void OnDestroy() { BluetoothD.controlTarget = null; } void initGameMode() { if (gameMode == 1) { this.gameMode1 = new GameMode1(); this.gameMode1.init(this); BluetoothD.controlTarget = GameObject.Find("CameraRoot"); } } public void hitTarget(int score) { if (gameMode == 1) { this.gameMode1.hitTarget(this, score); } } public bool checkFinish() { if (gameMode == 1) { return this.gameMode1.checkFinish(this); } return false; } public void Pause() { Time.timeScale = 0; } public void Resume() { Time.timeScale = 1; } public void StopGame() { Destroy(GameObject.FindObjectOfType()); } } /**闯关模式 */ public class GameMode1 { public static int level; public int arrowCount = 3; public int arrowCountMax = 3; public int score = 0; public int oneStarScore = 8; public bool finish; public void init(GameMgr gameMgr) { GameObject gv1 = Resources.Load("Prefabs/Views/ChallengeGameView"); GameObject.Instantiate(gv1, Vector3.zero, new Quaternion()); //debug TargetBody tb = GameObject.Find("GameArea/010/TargetBody").GetComponent(); TargetBody tb1 = GameObject.Find("GameArea/010 (1)/TargetBody").GetComponent(); // TargetBody tb2 = GameObject.Find("GameArea/010 (2)/TargetBody").GetComponent(); GameObject.Find("Main Camera/ArmBow").GetComponent().validTargets.Add(tb); GameObject.Find("Main Camera/ArmBow").GetComponent().validTargets.Add(tb1); // GameObject.Find("Main Camera/ArmBow").GetComponent().validTargets.Add(tb2); } public void hitTarget(GameMgr gameMgr, int score) { // this.score += score; // this.arrowCount -= 1; // ChallengeGameView.ins.arrows.text = this.arrowCount + "/" + this.arrowCountMax; } public bool checkFinish(GameMgr gameMgr) { if (this.finish) return true; if (this.arrowCount <= 0) { this.finish = true; gameMgr.gameOver = true; gameMgr.StopGame(); GameObject gwv1 = Resources.Load("Prefabs/Views/GameResultView"); GameObject.Instantiate(gwv1, Vector3.zero, new Quaternion()); return true; } return false; } public GameWinResult1 getWinResult() { GameWinResult1 result = new GameWinResult1(); result.starCount = this.score / this.oneStarScore; result.score = this.score; string key = "Challenge_Star_"; int star = PlayerPrefs.GetInt(key + level, 0); if (result.starCount > star) { PlayerPrefs.SetInt(key + level, result.starCount); } return result; } } public class GameWinResult1 { public int starCount; public int score; }