AIDispatcherComponentSystem.cs 1.5 KB

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