public void OnDrawGizmos() { if (Application.isPlaying == false || _spatialHash.IsCreated == false) { return; } if (UnityEngine.Time.realtimeSinceStartup - _timeLastRefresh > RefreshTime) { RefreshLinks(); } foreach (var l in _links) { DrawCell(l.Key); if (ShowLink) { foreach (var item in l.Value) { DrawLink(l.Key, item); } } } if (ShowRay) { var startRayPosition = DebugRay.origin; var startCellBound = new Bounds(_spatialHash.GetPositionVoxel(_spatialHash.GetIndexVoxel(startRayPosition), true), _spatialHash.CellSize); var raySize = math.max(_spatialHash.WorldBounds.Size.x, math.max(_spatialHash.WorldBounds.Size.y, _spatialHash.WorldBounds.Size.z)); Gizmos.color = Color.yellow; Gizmos.DrawLine(startRayPosition, DebugRay.GetPoint(raySize)); T hit = default; if (_spatialHash.RayCast(DebugRay, ref hit)) { Gizmos.color = Color.blue; Gizmos.DrawCube(hit.GetCenter(), hit.GetSize()); } _voxelTraversed.Clear(); _voxelRay.RayCast(ref _rayDebug, DebugRay.origin, DebugRay.direction, raySize); Gizmos.color = new Color(0.88F, 0.6F, 0.1F, 0.4F); foreach (var voxel in _voxelTraversed) { var position = _spatialHash.GetPositionVoxel(voxel, true); Gizmos.DrawCube(position, _spatialHash.CellSize); } var rayOffsetted = new Ray(DebugRay.origin - (Vector3)(DebugRay.direction * _spatialHash.CellSize), DebugRay.direction); startCellBound.GetEnterPositionAABB(rayOffsetted, 1 << 25, out var enterPoint); Gizmos.color = Color.white; Gizmos.DrawCube(enterPoint, Vector3.one * 0.3F); startCellBound.GetExitPosition(rayOffsetted, 1 << 25, out var exitPoint); Gizmos.color = Color.white; Gizmos.DrawCube(exitPoint, Vector3.one * 0.3F); } }