UIEventComponent.cs 937 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ET.Client
  4. {
  5. /// <summary>
  6. /// 管理所有UI GameObject
  7. /// </summary>
  8. [CodeProcess]
  9. public class UIEventComponent: Singleton<UIEventComponent>, ISingletonAwake
  10. {
  11. public Dictionary<string, AUIEvent> UIEvents { get; } = new();
  12. public void Awake()
  13. {
  14. var uiEvents = CodeTypes.Instance.GetTypes(typeof (UIEventAttribute));
  15. foreach (Type type in uiEvents)
  16. {
  17. object[] attrs = type.GetCustomAttributes(typeof (UIEventAttribute), false);
  18. if (attrs.Length == 0)
  19. {
  20. continue;
  21. }
  22. UIEventAttribute uiEventAttribute = attrs[0] as UIEventAttribute;
  23. AUIEvent aUIEvent = Activator.CreateInstance(type) as AUIEvent;
  24. this.UIEvents.Add(uiEventAttribute.UIType, aUIEvent);
  25. }
  26. }
  27. }
  28. }