BattleCheckPoint.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using GameWorld;
  5. using UnityEngine;
  6. public class BattleCheckPoint : BaseBehaviour
  7. {
  8. private void Awake()
  9. {
  10. for (int i = 0; i < this.fileId.Count; i++)
  11. {
  12. string sceneName = LevelManager.SceneName;
  13. string path = string.Format("Level/{0}", sceneName);
  14. string name = string.Format("{0}.{1}", sceneName, this.fileId[i]);
  15. LevelEnemyData value = Asset.DeserializeFromFile<LevelEnemyData>(path, name);
  16. this._levelEnemyData.Add(this.fileId[i], value);
  17. }
  18. }
  19. private void OnEnable()
  20. {
  21. this.queue = base.GetComponent<EnemyQueue>();
  22. }
  23. private void Start()
  24. {
  25. if (!this.PointData.canMultiTrigger && R.GameData.BattleZoneDict.ContainsKey(base.gameObject.name))
  26. {
  27. this.isBattleOver = R.GameData.BattleZoneDict[base.gameObject.name];
  28. }
  29. }
  30. private void Update()
  31. {
  32. if (!this.isBattleOver)
  33. {
  34. if (this.isOpenBattleZone && this.noEnemyTime > 0.5f && this.fileId.Count > this.currentId)
  35. {
  36. this.noEnemyTime = 0f;
  37. base.StartCoroutine(this.GenerateEnemyRushOneAfterOne(this.fileId[this.currentId], this.PointData.HasWall));
  38. this.currentId++;
  39. }
  40. if (this.isOpenBattleZone && this.noEnemyTime > 1f && this.PointData.HasWall)
  41. {
  42. this.isBattleOver = true;
  43. this.LeftGate.GetComponent<BattleZoneGate>().DisAppear();
  44. this.RightGate.GetComponent<BattleZoneGate>().DisAppear();
  45. base.StartCoroutine(this.OpenArea());
  46. }
  47. else if (!this.PointData.HasWall && ((this.isOpenBattleZone && this.noEnemyTime > 0.3f) || R.Player.IsNearSceneGate()))
  48. {
  49. base.StartCoroutine(this.OpenArea());
  50. }
  51. if (this.useNoEnemyTime)
  52. {
  53. if (this.PointData.HasWall)
  54. {
  55. this.rect.xMin = this.LeftGate.position.x - 5f;
  56. this.rect.xMax = this.RightGate.position.x + 5f;
  57. this.rect.yMin = Mathf.Min(this.LeftGate.position.y, this.RightGate.position.y) - 5f;
  58. this.rect.height = 50f;
  59. }
  60. else
  61. {
  62. this.rect.x = GameArea.MapRange.x;
  63. this.rect.y = GameArea.MapRange.y;
  64. this.rect.width = GameArea.MapRange.width;
  65. this.rect.height = GameArea.MapRange.height;
  66. }
  67. if (!R.Enemy.HasEnemyInRect(this.rect) && (this.queue.GetEnemyCount() <= 0 || this.queue.queueData.CheckEnemy != EnemyType.未定))
  68. {
  69. this.noEnemyTime += Time.deltaTime;
  70. }
  71. else
  72. {
  73. this.noEnemyTime = 0f;
  74. }
  75. }
  76. }
  77. }
  78. private IEnumerator OpenArea()
  79. {
  80. this.isOpenBattleZone = false;
  81. this.ExitBattleMode();
  82. if (!R.GameData.BattleZoneDict.ContainsKey(base.gameObject.name))
  83. {
  84. R.GameData.BattleZoneDict.Add(base.gameObject.name, true);
  85. }
  86. yield return new WaitForSeconds(0.5f);
  87. GameArea.CameraRange.xMin = GameArea.MapRange.min.x;
  88. GameArea.CameraRange.xMax = GameArea.MapRange.max.x;
  89. GameArea.PlayerRange.xMin = GameArea.MapRange.min.x - 1f;
  90. GameArea.PlayerRange.xMax = GameArea.MapRange.max.x + 1f;
  91. EventManager.PostEvent<BattleCheckPoint, BattleEventArgs>("Battle", this, BattleEventArgs.End);
  92. yield break;
  93. }
  94. private void ExitBattleMode()
  95. {
  96. if (R.Mode.IsInBattleMode())
  97. {
  98. R.Mode.ExitMode(Mode.AllMode.Battle);
  99. }
  100. }
  101. public void InitGameArea()
  102. {
  103. if (this.PointData.HasWall)
  104. {
  105. this.LeftGate.GetComponent<BattleZoneGate>().Appear();
  106. this.RightGate.GetComponent<BattleZoneGate>().Appear();
  107. GameArea.CameraRange.xMin = this.LeftGate.position.x;
  108. GameArea.CameraRange.xMax = this.RightGate.position.x;
  109. GameArea.EnemyRange.xMin = this.LeftGate.position.x;
  110. GameArea.EnemyRange.xMax = this.RightGate.position.x;
  111. GameArea.PlayerRange.xMin = this.LeftGate.Find("PlayerLimitPosLX").transform.position.x;
  112. GameArea.PlayerRange.xMax = this.RightGate.Find("PlayerLimitPosRX").transform.position.x;
  113. }
  114. else
  115. {
  116. GameArea.EnemyRange.xMin = GameArea.MapRange.min.x + 15f;
  117. GameArea.EnemyRange.xMax = GameArea.MapRange.max.x - 15f;
  118. }
  119. }
  120. private IEnumerator GenerateEnemyRushOneAfterOne(int num, bool canShake)
  121. {
  122. if (this._levelEnemyData.ContainsKey(num))
  123. {
  124. EventManager.PostEvent<BattleCheckPoint, BattleRushEventArgs>("BattleRush", this, new BattleRushEventArgs(num, this.currentId));
  125. LevelEnemyData levelEnemyData = this._levelEnemyData[num];
  126. foreach (EnemyJsonObject enemyJsonObject in levelEnemyData.enemyJsonObject)
  127. {
  128. GameObject e = R.Enemy.Generate(enemyJsonObject.name, new Vector2?(enemyJsonObject.position), this.PointData.HasWall, true);
  129. e.GetComponent<EnemyAttribute>().id = enemyJsonObject.guid;
  130. if (canShake)
  131. {
  132. SingletonMono<CameraController>.Instance.CameraShake(0.13333334f, 0.2f, CameraController.ShakeTypeEnum.Rect, false);
  133. }
  134. yield return new WaitForSeconds(0.5f);
  135. }
  136. R.SceneData.CanAIRun = true;
  137. this.useNoEnemyTime = true;
  138. this.queue.queueData = levelEnemyData.enemyQueueData;
  139. }
  140. else
  141. {
  142. Log.Warning(string.Format("关卡{0}第{1}波敌人尚未设置", LevelManager.SceneName, num));
  143. }
  144. yield break;
  145. }
  146. [SerializeField]
  147. public CheckPointData PointData;
  148. public List<int> fileId = new List<int>();
  149. public Transform LeftGate;
  150. public Transform RightGate;
  151. public bool isOpenBattleZone;
  152. public bool isBattleOver;
  153. private readonly Dictionary<int, LevelEnemyData> _levelEnemyData = new Dictionary<int, LevelEnemyData>();
  154. private float noEnemyTime = 0.6f;
  155. private bool useNoEnemyTime;
  156. private int currentId;
  157. private Rect rect;
  158. private EnemyQueue queue;
  159. }