ChallengeGameMode.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. //剩余的可用箭矢数量
  21. public int arrowCount = 5;
  22. //倒计时
  23. public float time = 60;
  24. public ChallengeGameMode(GameMgr gameMgr) : base(gameMgr) {
  25. //变量初始化
  26. animalsBaseT = GameObject.Find("Animals").transform;
  27. hunterT = this.gameMgr.GetComponentInChildren<ArmBow>().transform;
  28. //监听箭的射出,统计剩余的箭数
  29. GameEventCenter.ins.onBowArrowShootOut += delegate(ArmBow armBow, Arrow arrow) {
  30. if (arrowCount > 0) {
  31. arrowCount--;
  32. }
  33. };
  34. }
  35. public override bool DoNextShoot() {
  36. if (GameMgr.ins.gameOver) return false;
  37. if (animalCount == 0 || arrowCount == 0) {
  38. AnnounceGameOver();
  39. return false;
  40. }
  41. return true;
  42. }
  43. public override object[] Settle() {
  44. return new object[]{animalCount == 0 ? "胜利" : "失败"};
  45. }
  46. public override void Update() {
  47. if (gameMgr.gameOver || pauseTimeCounting) return;
  48. if (this.time > 0) {
  49. this.time -= Time.deltaTime;
  50. } else {
  51. this.time = 0;
  52. AnnounceGameOver();
  53. }
  54. }
  55. //添加关卡选择界面
  56. protected void AddSelectLevelView() {
  57. this.gameMgr.transform.Find("HuntGameSelectLevelView").gameObject.SetActive(true);
  58. }
  59. //宣布游戏结束
  60. protected void AnnounceGameOver() {
  61. gameMgr.StopGame();
  62. //添加结算界面
  63. this.gameMgr.transform.Find("HunterGameSettleView").gameObject.SetActive(true);
  64. }
  65. public abstract void SetLevel(int level);
  66. }