ChallengeGameMode.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 (banOnBowArrowShootOut) return;
  38. if (arrowCount > 0) {
  39. arrowCount--;
  40. }
  41. };
  42. if (enterNextLevel != null) {
  43. nextLevel = enterNextLevel;
  44. enterNextLevel = null;
  45. }
  46. }
  47. public override bool DoNextShoot() {
  48. if (GameMgr.ins.gameOver) return false;
  49. if (animalCount == 0 || arrowCount == 0) {
  50. AnnounceGameOver();
  51. return false;
  52. }
  53. return true;
  54. }
  55. public override object[] Settle() {
  56. return new object[]{animalCount == 0 ? "胜利" : "失败"};
  57. }
  58. public override void Update() {
  59. if (gameMgr.gameOver || pauseTimeCounting) return;
  60. if (this.time > 0) {
  61. this.time -= Time.deltaTime;
  62. } else {
  63. this.time = 0;
  64. AnnounceGameOver();
  65. }
  66. }
  67. //添加关卡选择界面
  68. protected void AddSelectLevelView() {
  69. this.gameMgr.transform.Find("HuntGameSelectLevelView").gameObject.SetActive(true);
  70. }
  71. //添加通用游戏界面
  72. public void AddHuntGameView() {
  73. this.gameMgr.transform.Find("HunterGameView").gameObject.SetActive(true);
  74. }
  75. //宣布游戏结束
  76. protected void AnnounceGameOver() {
  77. gameMgr.StopGame();
  78. //添加结算界面
  79. this.gameMgr.transform.Find("HunterGameSettleView").gameObject.SetActive(true);
  80. }
  81. public abstract void SetLevel(int level);
  82. //当前挑战的关卡是否为狼关卡
  83. public static bool IsChallengeWolf() {
  84. return GameMgr.gameType == 5 || GameMgr.gameType == 8 || GameMgr.gameType == 12;
  85. }
  86. #region //网络联机新增参数
  87. public bool banOnBowArrowShootOut = false;
  88. #endregion
  89. }