NavigationMesh.cs 978 B

123456789101112131415161718192021222324252627282930313233343536
  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. int count;
  12. var ptr = urho_navigationmesh_findpath(Handle, start, end, out count);
  13. if (ptr == IntPtr.Zero)
  14. return new Vector3[0];
  15. var res = new Vector3[count];
  16. int structSize = Marshal.SizeOf(typeof(Vector3));
  17. for (int i = 0; i < count; i++)
  18. {
  19. IntPtr data = new IntPtr(ptr.ToInt64() + structSize * i);
  20. Vector3 item = (Vector3)Marshal.PtrToStructure(data, typeof(Vector3));
  21. res[i] = item;
  22. }
  23. return res;
  24. }
  25. public unsafe Vector3 FindNearestPoint(Vector3 hitPos, Vector3 vector3)
  26. {
  27. return FindNearestPoint(hitPos, vector3, null, null);
  28. }
  29. }
  30. }