| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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 initGameMode() {
- if (gameMode == 1)
- {
- this.gameMode1 = new GameMode1();
- this.gameMode1.init(this);
- }
- }
- 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<BowCamera>());
- }
- }
- /**闯关模式 */
- 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<GameObject>("Prefabs/Views/ChallengeGameView");
- GameObject.Instantiate(gv1, Vector3.zero, new Quaternion());
- //debug
- TargetBody tb = GameObject.Find("GameArea/010/TargetBody").GetComponent<TargetBody>();
- TargetBody tb1 = GameObject.Find("GameArea/010 (1)/TargetBody").GetComponent<TargetBody>();
- // TargetBody tb2 = GameObject.Find("GameArea/010 (2)/TargetBody").GetComponent<TargetBody>();
- GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb);
- GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb1);
- // GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().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<GameObject>("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;
- }
|