# C# Unity ESP & Bounding Box Visualization Framework A high-performance C# framework demonstrating real-time in-game bounding box calculations, collider screen projections, Unity `Animator` skeleton bone rendering, and distance-scaled name tags using Unity's `OnGUI` and `Camera.WorldToScreenPoint`. ## Features - **3D Bounding Box Calculation**: Projects the 8 corner vertices of world-space `Bounds` into screen space and renders 12 connected wireframe edges. - **2D Screen-Aligned Box**: Computes tight 2D screen bounding rectangles derived from 3D collider extents. - **Skeleton & Bone ESP**: Traverses `Animator.GetBoneTransform(HumanBodyBones)` to render a full anatomical humanoid skeleton. - **Name & Distance Tags**: Renders formatted text labels and health bars scaled by camera distance. - **Occlusion & Viewport Clipping**: Automatically culls entities positioned behind the active camera frustum (`Z > 0`). ## Mathematical Projection Pipeline ### 1. 3D Bounding Box Given an entity bounding box with center $C = (c_x, c_y, c_z)$ and extents $E = (e_x, e_y, e_z)$, the 8 world-space corners are computed: $$V_{i,j,k} = C + (\pm e_x, \pm e_y, \pm e_z)$$ Each vertex is transformed to screen space via `Camera.WorldToScreenPoint(V)` and inverted along the Y-axis for Unity GUI coordinates: $$y_{gui} = \text{Screen.height} - y_{screen}$$ ### 2. Bone Skeleton Graph Humanoid bones are queried using `HumanBodyBones` and connected as line segments: - **Head & Spine**: `Head` -> `Neck` -> `Chest` -> `Spine` -> `Hips` - **Left Arm**: `Neck` -> `LeftShoulder` -> `LeftUpperArm` -> `LeftLowerArm` -> `LeftHand` - **Right Arm**: `Neck` -> `RightShoulder` -> `RightUpperArm` -> `RightLowerArm` -> `RightHand` - **Left Leg**: `Hips` -> `LeftUpperLeg` -> `LeftLowerLeg` -> `LeftFoot` - **Right Leg**: `Hips` -> `RightUpperLeg` -> `RightLowerLeg` -> `RightFoot` ## Usage Attach `ESPManager` to an active GameObject with camera reference: ```csharp using UnityEngine; using CSharpESP; public class ExampleUsage : MonoBehaviour { private void Start() { ESPManager.Instance.EnableBox3D = true; ESPManager.Instance.EnableBones = true; ESPManager.Instance.EnableNameTags = true; } } ``` ## Structure ``` src/ ├── Drawing/ │ └── RenderHelper.cs # 2D line, box, string, and texture drawing primitives ├── Entities/ │ └── ESPTarget.cs # Target tracking component with collider/animator bindings ├── Renderers/ │ ├── BoneRenderer.cs # HumanBodyBones skeleton graph traversal & rendering │ ├── Box2DRenderer.cs # Screen-aligned 2D rectangle & corner brackets │ ├── Box3DRenderer.cs # 8-vertex 12-edge 3D wireframe bounding box │ └── NameTagRenderer.cs # Distance-scaled text label & health bar ├── ESPManager.cs # Main MonoBehaviour dispatcher └── MathUtils.cs # Coordinate projection & bounding math ``` ## License Released under the [MIT License](LICENSE).