Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / event / EventFactory.cs
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4.  
  5. /// <summary>
  6. /// 事件工厂, 用于统一绑定事件与销毁的情况
  7. /// </summary>
  8. public class EventFactory
  9. {
  10. private List<EventBinder> _binders = new List<EventBinder>();
  11.  
  12. /// <summary>
  13. /// 添加监听事件
  14. /// </summary>
  15. public void AddEventListener(EventEnum eventType, Action<object> callback)
  16. {
  17. _binders.Add(EventManager.AddEventListener(eventType, callback));
  18. }
  19.  
  20. /// <summary>
  21. /// 移除所有监听事件
  22. /// </summary>
  23. public void RemoveAllEventListener()
  24. {
  25. foreach (var eventBinder in _binders)
  26. {
  27. EventManager.RemoveEventListener(eventBinder);
  28. }
  29. _binders.Clear();
  30. }
  31. }