SpawnerSystem.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityGameFramework.Runtime;
  5. using GameFramework.Event;
  6. using BattleDefine;
  7. namespace YLBattle
  8. {
  9. /// </summary>
  10. public class SpawnerSystem : MonoBehaviour
  11. {
  12. /// <summary>
  13. /// 单键
  14. /// </summary>
  15. private static SpawnerSystem m_Instance;
  16. private Dictionary<int, ZoneSpawnerLogic> _spawnerDict;
  17. private EBattleSceneType _battleType;
  18. public int crateGroupNowNum;
  19. public int crateGroupMax;
  20. /// <summary>
  21. /// 单键
  22. /// </summary>
  23. public static SpawnerSystem Instance
  24. {
  25. get
  26. {
  27. if (m_Instance == null)
  28. {
  29. m_Instance = GameObject.Find("SpawnerSystem").AddComponent<SpawnerSystem>();
  30. }
  31. return m_Instance;
  32. }
  33. }
  34. public void Awake()
  35. {
  36. _spawnerDict = new Dictionary<int, ZoneSpawnerLogic>();
  37. crateGroupNowNum = 0;
  38. crateGroupMax = 0;
  39. }
  40. public void Start()
  41. {
  42. }
  43. public void Init()
  44. {
  45. Reset();
  46. }
  47. public void Add(ZoneSpawnerLogic spawner)
  48. {
  49. _spawnerDict[spawner.spawnerInfo.index] = spawner;
  50. }
  51. public ZoneSpawnerLogic GetSpawnerByIndex(int index)
  52. {
  53. return _spawnerDict[index];
  54. }
  55. public Dictionary<int, ZoneSpawnerLogic> GetAllSpawner()
  56. {
  57. return _spawnerDict;
  58. }
  59. public void OpenSystem()
  60. {
  61. foreach(var item in _spawnerDict)
  62. {
  63. item.Value.IsClose = false;
  64. }
  65. }
  66. public void CloseSystem()
  67. {
  68. foreach (var item in _spawnerDict)
  69. {
  70. item.Value.IsClose = true;
  71. }
  72. }
  73. public void Reset()
  74. {
  75. foreach(var item in _spawnerDict)
  76. {
  77. item.Value.Reset();
  78. }
  79. }
  80. public void SetBattleType(EBattleSceneType btType)
  81. {
  82. _battleType = btType;
  83. }
  84. public EBattleSceneType GetBattleType()
  85. {
  86. return _battleType;
  87. }
  88. public bool IsCloseAllSpawner()
  89. {
  90. foreach(var item in _spawnerDict)
  91. {
  92. if(item.Value.GetAllRole().Count > 0)
  93. {
  94. return false;
  95. }
  96. }
  97. return true;
  98. }
  99. public bool IsLastSpawner()
  100. {
  101. foreach (var item in _spawnerDict)
  102. {
  103. if (!item.Value.IsLastNode())
  104. {
  105. return false;
  106. }
  107. }
  108. return true;
  109. }
  110. public void EnableSpawnerByIndex(int index)
  111. {
  112. _spawnerDict[index].EnableSpawner();
  113. }
  114. public void EnableSpawnerByNext()
  115. {
  116. foreach (var item in _spawnerDict)
  117. {
  118. if (!item.Value.IsCreateFinish())
  119. {
  120. item.Value.EnableSpawner();
  121. break;
  122. }
  123. }
  124. }
  125. }
  126. }