ChallengeGameMode.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public abstract class ChallengeGameMode : GameMode
  5. {
  6. //动物类型ID {0:野兔,1:野鸡,2:野狼}
  7. public int animalTypeID = 0;
  8. //该关卡的动物预制体
  9. protected GameObject animalPrefab;
  10. //猎人的变换组件
  11. protected Transform hunterT;
  12. //动物地基的变换组件
  13. protected Transform animalsBaseT;
  14. //场景中活着的动物
  15. protected HashSet<TargetAnimal> animalSet = new HashSet<TargetAnimal>();
  16. //场景中最多同时存在多少只活着的动物
  17. protected int maxAnimalCountAtTheSameTime = 2;
  18. //剩余的动物数量(包含场中活着的和后续未出场的)
  19. public int animalCount = 0;
  20. public int animalCountMax = 0;
  21. //剩余的可用箭矢数量
  22. public int arrowCount = 0;
  23. public int arrowCountMax = 0;
  24. //倒计时
  25. public float time = 60;
  26. //当前关卡等级
  27. public int currentlevel;
  28. //上一关点击进入下一关,会把信息记录到这
  29. public static string enterNextLevel;
  30. public string nextLevel;
  31. public ChallengeGameMode(GameMgr gameMgr) : base(gameMgr) {
  32. //变量初始化
  33. animalsBaseT = GameObject.Find("Animals").transform;
  34. hunterT = this.gameMgr.GetComponentInChildren<ArmBow>().transform;
  35. //监听箭的射出,统计剩余的箭数
  36. GameEventCenter.ins.onBowArrowShootOut += delegate(ArmBow armBow, Arrow arrow) {
  37. if (arrowCount > 0) {
  38. arrowCount--;
  39. }
  40. };
  41. if (enterNextLevel != null) {
  42. nextLevel = enterNextLevel;
  43. enterNextLevel = null;
  44. }
  45. }
  46. public override bool DoNextShoot() {
  47. if (GameMgr.ins.gameOver) return false;
  48. if (animalCount == 0 || arrowCount == 0) {
  49. AnnounceGameOver();
  50. return false;
  51. }
  52. return true;
  53. }
  54. public override object[] Settle() {
  55. return new object[]{animalCount == 0 ? "胜利" : "失败"};
  56. }
  57. public override void Update() {
  58. if (gameMgr.gameOver || pauseTimeCounting) return;
  59. if (this.time > 0) {
  60. this.time -= Time.deltaTime;
  61. } else {
  62. this.time = 0;
  63. AnnounceGameOver();
  64. }
  65. }
  66. //添加关卡选择界面
  67. protected void AddSelectLevelView() {
  68. this.gameMgr.transform.Find("HuntGameSelectLevelView").gameObject.SetActive(true);
  69. }
  70. //添加通用游戏界面
  71. public void AddHuntGameView() {
  72. this.gameMgr.transform.Find("HunterGameView").gameObject.SetActive(true);
  73. }
  74. //宣布游戏结束
  75. protected void AnnounceGameOver() {
  76. gameMgr.StopGame();
  77. //添加结算界面
  78. this.gameMgr.transform.Find("HunterGameSettleView").gameObject.SetActive(true);
  79. }
  80. public abstract void SetLevel(int level);
  81. }