using UnityEngine; [ExecuteAlways] public class VoxelTreeDebugger : MonoBehaviour { public bool enableDraw = false; [Header("Tree reference")] public OctreeNode root; // Reference to your voxel tree root [Header("Debug settings")] public bool drawLeavesOnly = true; // Draw only leaf nodes public int maxDepthToDraw = 6; // Limit drawing depth public Color emptyColor = new Color(0f, 0.5f, 1f, 0.2f); public Color solidColor = new Color(1f, 0f, 0f, 0.5f); public Color mixedColor = new Color(1f, 1f, 0f, 0.4f); void OnDrawGizmos() { if (root != null && enableDraw) { DrawNode(root, 0); } } private void DrawNode(OctreeNode node, int depth) { if (node == null || depth > maxDepthToDraw) return; // Set color based on node type if (node.isLeaf) { Gizmos.color = node.isOccupied ? solidColor : emptyColor; Gizmos.DrawWireCube(node.bounds.center, node.bounds.size); if (node.isOccupied) Gizmos.DrawCube(node.bounds.center, node.bounds.size * 0.95f); } else { Gizmos.color = mixedColor; if (!drawLeavesOnly) Gizmos.DrawWireCube(node.bounds.center, node.bounds.size); // Recursively draw children foreach (var child in node.children) { DrawNode(child, depth + 1); } } } }