AIDispatcherComponentSystem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. namespace ET
  3. {
  4. [FriendOf(typeof(AIDispatcherComponent))]
  5. public static class AIDispatcherComponentSystem
  6. {
  7. [ObjectSystem]
  8. public class AIDispatcherComponentAwakeSystem: AwakeSystem<AIDispatcherComponent>
  9. {
  10. protected override void Awake(AIDispatcherComponent self)
  11. {
  12. AIDispatcherComponent.Instance = self;
  13. self.Load();
  14. }
  15. }
  16. [ObjectSystem]
  17. public class AIDispatcherComponentLoadSystem: LoadSystem<AIDispatcherComponent>
  18. {
  19. protected override void Load(AIDispatcherComponent self)
  20. {
  21. self.Load();
  22. }
  23. }
  24. [ObjectSystem]
  25. public class AIDispatcherComponentDestroySystem: DestroySystem<AIDispatcherComponent>
  26. {
  27. protected override void Destroy(AIDispatcherComponent self)
  28. {
  29. self.AIHandlers.Clear();
  30. AIDispatcherComponent.Instance = null;
  31. }
  32. }
  33. private static void Load(this AIDispatcherComponent self)
  34. {
  35. self.AIHandlers.Clear();
  36. var types = EventSystem.Instance.GetTypes(typeof (AIHandlerAttribute));
  37. foreach (Type type in types)
  38. {
  39. AAIHandler aaiHandler = Activator.CreateInstance(type) as AAIHandler;
  40. if (aaiHandler == null)
  41. {
  42. Log.Error($"robot ai is not AAIHandler: {type.Name}");
  43. continue;
  44. }
  45. self.AIHandlers.Add(type.Name, aaiHandler);
  46. }
  47. }
  48. }
  49. }