NavmeshComponentSystem.cs 1009 B

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