GameMgr.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using UnityEngine;
  2. public class GameMgr : MonoBehaviour
  3. {
  4. public static int gameMode = 1;
  5. public GameMode1 gameMode1;
  6. public bool gameOver = false;
  7. public static GameMgr ins;
  8. void Start()
  9. {
  10. ins = this;
  11. AudioMgr.init();
  12. this.initGameMode();
  13. }
  14. void initGameMode() {
  15. if (gameMode == 1)
  16. {
  17. this.gameMode1 = new GameMode1();
  18. this.gameMode1.init(this);
  19. }
  20. }
  21. public void hitTarget(int score) {
  22. if (gameMode == 1) {
  23. this.gameMode1.hitTarget(this, score);
  24. }
  25. }
  26. public bool checkFinish() {
  27. if (gameMode == 1) {
  28. return this.gameMode1.checkFinish(this);
  29. }
  30. return false;
  31. }
  32. public void Pause() {
  33. Time.timeScale = 0;
  34. }
  35. public void Resume() {
  36. Time.timeScale = 1;
  37. }
  38. public void StopGame() {
  39. Destroy(GameObject.FindObjectOfType<BowCamera>());
  40. }
  41. }
  42. /**闯关模式 */
  43. public class GameMode1 {
  44. public static int level;
  45. public int arrowCount = 3;
  46. public int arrowCountMax = 3;
  47. public int score = 0;
  48. public int oneStarScore = 8;
  49. public bool finish;
  50. public void init(GameMgr gameMgr) {
  51. GameObject gv1 = Resources.Load<GameObject>("Prefabs/Views/ChallengeGameView");
  52. GameObject.Instantiate(gv1, Vector3.zero, new Quaternion());
  53. //debug
  54. TargetBody tb = GameObject.Find("GameArea/010/TargetBody").GetComponent<TargetBody>();
  55. TargetBody tb1 = GameObject.Find("GameArea/010 (1)/TargetBody").GetComponent<TargetBody>();
  56. // TargetBody tb2 = GameObject.Find("GameArea/010 (2)/TargetBody").GetComponent<TargetBody>();
  57. GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb);
  58. GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb1);
  59. // GameObject.Find("Main Camera/ArmBow").GetComponent<ArmBow>().validTargets.Add(tb2);
  60. }
  61. public void hitTarget(GameMgr gameMgr, int score) {
  62. // this.score += score;
  63. // this.arrowCount -= 1;
  64. // ChallengeGameView.ins.arrows.text = this.arrowCount + "/" + this.arrowCountMax;
  65. }
  66. public bool checkFinish(GameMgr gameMgr) {
  67. if (this.finish) return true;
  68. if (this.arrowCount <= 0) {
  69. this.finish = true;
  70. gameMgr.gameOver = true;
  71. gameMgr.StopGame();
  72. GameObject gwv1 = Resources.Load<GameObject>("Prefabs/Views/GameResultView");
  73. GameObject.Instantiate(gwv1, Vector3.zero, new Quaternion());
  74. return true;
  75. }
  76. return false;
  77. }
  78. public GameWinResult1 getWinResult() {
  79. GameWinResult1 result = new GameWinResult1();
  80. result.starCount = this.score / this.oneStarScore;
  81. result.score = this.score;
  82. string key = "Challenge_Star_";
  83. int star = PlayerPrefs.GetInt(key + level, 0);
  84. if (result.starCount > star)
  85. {
  86. PlayerPrefs.SetInt(key + level, result.starCount);
  87. }
  88. return result;
  89. }
  90. }
  91. public class GameWinResult1 {
  92. public int starCount;
  93. public int score;
  94. }