Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void OnDrawGizmos()
- {
- if (!enabled)
- return;
- if (samplePoint != null)
- {
- Gizmos.color = Color.red;
- var samplePos = samplePoint.position;
- Gizmos.DrawWireSphere(samplePos, .05f);
- //super advanced
- var xform = transform;
- var localUp = xform.up;
- Vector3 hitPoint = samplePos - localUp
- * Vector3.Dot(
- samplePos - xform.position,
- localUp);
- //the hit point in local terrain space
- var hitPointLocal = transform.InverseTransformPoint(hitPoint);
- //what point was hit in the overall terrain
- var flooredHit = new Vector2Int(
- Mathf.FloorToInt(hitPointLocal.x / size.x * TerrainSubdivs * chunkSubdivs),
- Mathf.FloorToInt(hitPointLocal.z / size.y * TerrainSubdivs * chunkSubdivs));
- //what point was hit inside the chunk
- var flooredHitChunk = new Vector2Int(flooredHit.x % chunkSubdivs,flooredHit.y % chunkSubdivs);
- // the 2d position of the chunk
- Vector2Int chunkPosition = new Vector2Int(
- flooredHit.x / chunkSubdivs,
- flooredHit.y / chunkSubdivs
- );
- var ChunkArray1DIndex = chunkPosition.x + chunkPosition.y * TerrainSubdivs;
- Debug.Log($"flooredHit: {flooredHit.ToString()} " +
- $"flooredHitChunk: {flooredHitChunk.ToString()} " +
- $"chunkPosition: {chunkPosition.ToString()} " +
- $"chunkArrayIndex: {ChunkArray1DIndex.ToString()}");
- chunks[chunkPosition.x, chunkPosition.y].DrawPointGizmo(flooredHitChunk);
- Gizmos.DrawLine(samplePos, hitPoint);
- }
- if (chunks == null) return;
- Gizmos.matrix = transform.localToWorldMatrix;
- foreach (var chunk in chunks) chunk.DrawGizmo(settings.pointSize, quad);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement