public void SpatialHashQuerry() { var cellSize = new float3(1F); SpatialHash <Item> sh = new SpatialHash <Item>(new Bounds(new float3(15F), new float3(30F)), cellSize, 15, Allocator.Temp); var item = new Item { Center = new float3(5.5F), Size = new float3(1.1F) }; sh.Add(ref item); Assert.AreEqual(1, sh.ItemCount); Assert.AreEqual(3 * 3 * 3, sh.BucketItemCount); var results = new NativeList <Item>(5, Allocator.TempJob); var bounds = new Bounds(item.GetCenter(), item.GetSize()); sh.CalculStartEndIteration(bounds, out var start, out var end); var hashPosition = new int3(0F); for (int x = start.x; x < end.x; ++x) { hashPosition.x = x; for (int y = start.y; y < end.y; ++y) { hashPosition.y = y; for (int z = start.z; z < end.z; ++z) { hashPosition.z = z; var querryBound = new Bounds(sh.GetPositionVoxel(hashPosition, true), cellSize * 0.95F); results.Clear(); sh.Query(querryBound, results); Assert.AreEqual(1, results.Length); Assert.AreEqual(item, results[0]); } } } //check clear result results.Dispose(); sh.Dispose(); }