AIDispatcherComponent.cs 956 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ET
  4. {
  5. [CodeProcess]
  6. public class AIDispatcherComponent: Singleton<AIDispatcherComponent>, ISingletonAwake
  7. {
  8. private readonly Dictionary<string, AAIHandler> aiHandlers = new();
  9. public void Awake()
  10. {
  11. var types = CodeTypes.Instance.GetTypes(typeof (AIHandlerAttribute));
  12. foreach (Type type in types)
  13. {
  14. AAIHandler aaiHandler = Activator.CreateInstance(type) as AAIHandler;
  15. if (aaiHandler == null)
  16. {
  17. Log.Error($"robot ai is not AAIHandler: {type.Name}");
  18. continue;
  19. }
  20. this.aiHandlers.Add(type.Name, aaiHandler);
  21. }
  22. }
  23. public AAIHandler Get(string key)
  24. {
  25. this.aiHandlers.TryGetValue(key, out var aaiHandler);
  26. return aaiHandler;
  27. }
  28. }
  29. }