NavmeshComponentSystem.cs 965 B

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