GameMgr.cs 3.3 KB

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