diff --git a/src/DotRecast.Detour/NavMesh.cs b/src/DotRecast.Detour/NavMesh.cs index f4c85a2..2f1fa8a 100644 --- a/src/DotRecast.Detour/NavMesh.cs +++ b/src/DotRecast.Detour/NavMesh.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Numerics; +using System.Runtime.InteropServices.ComTypes; using DotRecast.Core; using DotRecast.Detour.QueryResults; @@ -210,11 +211,10 @@ namespace DotRecast.Detour * The world position for the query. [(x, y, z)] * @return 2-element int array with (tx,ty) tile location */ - public int[] CalcTileLoc(Vector3f pos) + public void CalcTileLoc(Vector3f pos, out int tx, out int ty) { - int tx = (int)Math.Floor((pos.x - m_orig.x) / m_tileWidth); - int ty = (int)Math.Floor((pos.z - m_orig.z) / m_tileHeight); - return new int[] { tx, ty }; + tx = (int)Math.Floor((pos.x - m_orig.x) / m_tileWidth); + ty = (int)Math.Floor((pos.z - m_orig.z) / m_tileHeight); } public Result> GetTileAndPolyByRef(long refs) diff --git a/src/DotRecast.Detour/NavMeshQuery.cs b/src/DotRecast.Detour/NavMeshQuery.cs index 7c731d9..2ffa4f9 100644 --- a/src/DotRecast.Detour/NavMeshQuery.cs +++ b/src/DotRecast.Detour/NavMeshQuery.cs @@ -710,12 +710,9 @@ namespace DotRecast.Detour Vector3f bmin = center.Subtract(halfExtents); Vector3f bmax = center.Add(halfExtents); - int[] minxy = m_nav.CalcTileLoc(bmin); - int minx = minxy[0]; - int miny = minxy[1]; - int[] maxxy = m_nav.CalcTileLoc(bmax); - int maxx = maxxy[0]; - int maxy = maxxy[1]; + m_nav.CalcTileLoc(bmin, out var minx, out var miny); + m_nav.CalcTileLoc(bmax, out var maxx, out var maxy); + List tiles = new List(); for (int y = miny; y <= maxy; ++y) { diff --git a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs index 02932e2..5470c31 100644 --- a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs +++ b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs @@ -60,8 +60,8 @@ public class UnityAStarPathfindingImporterTest NavMesh mesh = LoadNavMesh("test_boundstree.zip"); Vector3f position = Vector3f.Of(387.52988f, 19.997f, 368.86282f); - int[] tilePos = mesh.CalcTileLoc(position); - long tileRef = mesh.GetTileRefAt(tilePos[0], tilePos[1], 0); + mesh.CalcTileLoc(position, out var tileX, out var tileY); + long tileRef = mesh.GetTileRefAt(tileX, tileY, 0); MeshTile tile = mesh.GetTileByRef(tileRef); MeshData data = tile.data; BVNode[] bvNodes = data.bvTree; @@ -137,4 +137,4 @@ public class UnityAStarPathfindingImporterTest using var os = new BinaryWriter(fs); writer.Write(os, mesh, RcByteOrder.LITTLE_ENDIAN, true); } -} +} \ No newline at end of file