NavmeshComponentSystem.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. namespace ET
  3. {
  4. [FriendOf(typeof(NavmeshComponent))]
  5. public static class NavmeshComponentSystem
  6. {
  7. public class AwakeSystem: AwakeSystem<NavmeshComponent>
  8. {
  9. protected override void Awake(NavmeshComponent self)
  10. {
  11. NavmeshComponent.Instance = self;
  12. }
  13. }
  14. public static long Get(this NavmeshComponent self, string name)
  15. {
  16. long ptr;
  17. if (self.Navmeshs.TryGetValue(name, out ptr))
  18. {
  19. return ptr;
  20. }
  21. byte[] buffer = EventSystem.Instance.Invoke<NavmeshComponent.RecastFileLoader, byte[]>(0, new NavmeshComponent.RecastFileLoader() {Name = name});
  22. if (buffer.Length == 0)
  23. {
  24. throw new Exception($"no nav data: {name}");
  25. }
  26. ptr = Recast.RecastLoadLong(name.GetHashCode(), buffer, buffer.Length);
  27. self.Navmeshs[name] = ptr;
  28. return ptr;
  29. }
  30. }
  31. }