NavmeshComponent.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ET
  4. {
  5. public class NavmeshComponent: Singleton<NavmeshComponent>, ISingletonAwake
  6. {
  7. public struct RecastFileLoader
  8. {
  9. public string Name { get; set; }
  10. }
  11. private readonly Dictionary<string, byte[]> navmeshs = new();
  12. public void Awake()
  13. {
  14. }
  15. public byte[] Get(string name)
  16. {
  17. lock (this)
  18. {
  19. if (this.navmeshs.TryGetValue(name, out byte[] bytes))
  20. {
  21. return bytes;
  22. }
  23. byte[] buffer =
  24. EventSystem.Instance.Invoke<NavmeshComponent.RecastFileLoader, byte[]>(
  25. new NavmeshComponent.RecastFileLoader() { Name = name });
  26. if (buffer.Length == 0)
  27. {
  28. throw new Exception($"no nav data: {name}");
  29. }
  30. this.navmeshs[name] = buffer;
  31. return buffer;
  32. }
  33. }
  34. }
  35. }