ChallengeGameMode.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /* 动物挑战关卡游戏模式-通用父类 */
  5. public abstract class ChallengeGameMode : GameMode
  6. {
  7. //动物类型ID {0:野兔,1:野鸡,2:野狼}
  8. public int animalTypeID = 0;
  9. //该关卡的动物预制体
  10. protected GameObject animalPrefab;
  11. //猎人的变换组件
  12. protected Transform hunterT;
  13. //动物地基的变换组件
  14. protected Transform animalsBaseT;
  15. //场景中活着的动物
  16. protected HashSet<TargetAnimal> animalSet = new HashSet<TargetAnimal>();
  17. //场景中最多同时存在多少只活着的动物
  18. protected int maxAnimalCountAtTheSameTime = 2;
  19. //剩余的动物数量(包含场中活着的和后续未出场的)
  20. public int animalCount = 0;
  21. public int animalCountMax = 0;
  22. //剩余的可用箭矢数量
  23. public int arrowCount = 0;
  24. public int arrowCountMax = 0;
  25. //倒计时
  26. public float time = 60;
  27. //当前关卡等级
  28. public int currentlevel;
  29. //上一关点击进入下一关,会把信息记录到这
  30. public static string enterNextLevel;
  31. public string nextLevel;
  32. public ChallengeGameMode(GameMgr gameMgr) : base(gameMgr) {
  33. //变量初始化
  34. animalsBaseT = GameObject.Find("Animals").transform;
  35. hunterT = this.gameMgr.GetComponentInChildren<ArmBow>().transform;
  36. //监听箭的射出,统计剩余的箭数
  37. GameEventCenter.ins.onBowArrowShootOut += delegate(ArmBow armBow, Arrow arrow) {
  38. if (banOnBowArrowShootOut) return;
  39. if (arrowCount > 0) {
  40. arrowCount--;
  41. }
  42. };
  43. if (enterNextLevel != null) {
  44. nextLevel = enterNextLevel;
  45. enterNextLevel = null;
  46. }
  47. }
  48. public override bool DoNextShoot() {
  49. if (GameMgr.ins.gameOver) return false;
  50. if (animalCount == 0 || arrowCount == 0) {
  51. AnnounceGameOver();
  52. return false;
  53. }
  54. return true;
  55. }
  56. public override object[] Settle() {
  57. return new object[]{animalCount == 0 ? "胜利" : "失败"};
  58. }
  59. public override void Update() {
  60. #if UNITY_EDITOR
  61. if (Input.GetKey(KeyCode.W) && !gameMgr.gameOver) { //win
  62. Debug.LogWarning("debug-win");
  63. gameMgr.gameOver = true;
  64. animalCount = 0;
  65. foreach (var item in animalSet)
  66. {
  67. GameObject.Destroy(item.gameObject);
  68. }
  69. AnnounceGameOver();
  70. }
  71. if (Input.GetKey(KeyCode.F) && !gameMgr.gameOver) { //fail
  72. gameMgr.gameOver = true;
  73. Debug.LogWarning("debug-fail");
  74. AnnounceGameOver();
  75. }
  76. #endif
  77. if (gameMgr.gameOver || pauseTimeCounting) return;
  78. if (this.time > 0) {
  79. if (GlobalData.pkMatchType == PKMatchType.None && UserSettings.ins.trainMode) {
  80. //单人且为训练模式,就不要倒计时了
  81. } else {
  82. this.time -= Time.deltaTime;
  83. }
  84. } else {
  85. this.time = 0;
  86. AnnounceGameOver();
  87. }
  88. }
  89. //添加关卡选择界面
  90. protected void AddSelectLevelView() {
  91. this.gameMgr.transform.Find("HuntGameSelectLevelView").gameObject.SetActive(true);
  92. }
  93. //添加通用游戏界面
  94. public void AddHuntGameView() {
  95. this.gameMgr.transform.Find("HunterGameView").gameObject.SetActive(true);
  96. }
  97. //宣布游戏结束
  98. protected void AnnounceGameOver() {
  99. gameMgr.StopGame();
  100. //添加结算界面
  101. this.gameMgr.transform.Find("HunterGameSettleView").gameObject.SetActive(true);
  102. }
  103. public abstract void SetLevel(int level);
  104. //当前挑战的关卡是否为狼关卡
  105. public static bool IsChallengeWolf() {
  106. return GameMgr.gameType == 5 || GameMgr.gameType == 8 || GameMgr.gameType == 12;
  107. }
  108. #region //网络联机新增参数
  109. public bool banOnBowArrowShootOut = false;
  110. #endregion
  111. }