NavigationMesh.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Urho.Navigation
  4. {
  5. partial class NavigationMesh
  6. {
  7. [DllImport(Consts.NativeImport, CallingConvention = CallingConvention.Cdecl)]
  8. internal extern static IntPtr urho_navigationmesh_findpath(IntPtr navMesh, Vector3 start, Vector3 end, out int count);
  9. public Vector3[] FindPath(Vector3 start, Vector3 end)
  10. {
  11. Runtime.ValidateRefCounted(this);
  12. int count;
  13. var ptr = urho_navigationmesh_findpath(Handle, start, end, out count);
  14. if (ptr == IntPtr.Zero)
  15. return new Vector3[0];
  16. var res = new Vector3[count];
  17. int structSize = Marshal.SizeOf(typeof(Vector3));
  18. for (int i = 0; i < count; i++)
  19. {
  20. IntPtr data = new IntPtr(ptr.ToInt64() + structSize * i);
  21. Vector3 item = (Vector3)Marshal.PtrToStructure(data, typeof(Vector3));
  22. res[i] = item;
  23. }
  24. return res;
  25. }
  26. public unsafe Vector3 FindNearestPoint(Vector3 hitPos, Vector3 vector3)
  27. {
  28. Runtime.ValidateRefCounted(this);
  29. return FindNearestPoint(hitPos, vector3, null, null);
  30. }
  31. }
  32. }