unreliablecode / CSharp-Unity-ESP-Framework
Openbaar
High-performance C# ESP framework for Unity โ 3D bounding boxes, 2D collider calculation, Animator skeleton bone tracking, and distance-scaled name tags.
main
1 Sterren
0 Vorken
0 Kijkers
Bijgewerkt 2 days ago
C#
100%
Code
Problemen
Pull-verzoeken 0
Betreft
Takken
Labels
Releases
Zoekopdracht
Bijdragers
Wiki
Inzichten
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using UnityEngine;
namespace CSharpESP
{
public static class MathUtils
{
/// <summary>
/// Converts a world coordinate into Unity GUI screen coordinates.
/// Returns false if the point is behind the camera frustum.
/// </summary>
public static bool WorldToScreen(Camera camera, Vector3 worldPos, out Vector2 screenPos)
{
screenPos = Vector2.zero;
if (camera == null) return false;
Vector3 viewPos = camera.WorldToScreenPoint(worldPos);
if (viewPos.z <= 0.01f)
{
return false;
}
// Invert Y coordinate for GUI coordinate space
screenPos = new Vector2(viewPos.x, Screen.height - viewPos.y);
return true;
}
/// <summary>
/// Calculates the 8 world-space corner vertices of an axis-aligned bounding box.
/// </summary>
public static Vector3[] GetBoundsVertices(Bounds bounds)
{
Vector3 center = bounds.center;
Vector3 ext = bounds.extents;
return new Vector3[8]
{
new Vector3(center.x - ext.x, center.y - ext.y, center.z - ext.z), // 0: Bottom-Left-Back
new Vector3(center.x + ext.x, center.y - ext.y, center.z - ext.z), // 1: Bottom-Right-Back
new Vector3(center.x + ext.x, center.y - ext.y, center.z + ext.z), // 2: Bottom-Right-Front
new Vector3(center.x - ext.x, center.y - ext.y, center.z + ext.z), // 3: Bottom-Left-Front
new Vector3(center.x - ext.x, center.y + ext.y, center.z - ext.z), // 4: Top-Left-Back
new Vector3(center.x + ext.x, center.y + ext.y, center.z - ext.z), // 5: Top-Right-Back
new Vector3(center.x + ext.x, center.y + ext.y, center.z + ext.z), // 6: Top-Right-Front
new Vector3(center.x - ext.x, center.y + ext.y, center.z + ext.z) // 7: Top-Left-Front
};
}
/// <summary>
/// Computes a screen-aligned 2D rectangle encapsulating the 3D bounds vertices.
/// </summary>
public static bool GetScreenRectFromBounds(Camera camera, Bounds bounds, out Rect screenRect)
{
screenRect = Rect.zero;
Vector3[] vertices = GetBoundsVertices(bounds);
float minX = float.MaxValue;
float maxX = float.MinValue;
float minY = float.MaxValue;
float maxY = float.MinValue;
bool anyVisible = false;
for (int i = 0; i < 8; i++)
{
if (WorldToScreen(camera, vertices[i], out Vector2 screenPoint))
{
minX = Mathf.Min(minX, screenPoint.x);
maxX = Mathf.Max(maxX, screenPoint.x);
minY = Mathf.Min(minY, screenPoint.y);
maxY = Mathf.Max(maxY, screenPoint.y);
anyVisible = true;
}
}
if (!anyVisible || maxX <= minX || maxY <= minY)
{
return false;
}
screenRect = new Rect(minX, minY, maxX - minX, maxY - minY);
return true;
}
/// <summary>
/// Calculates distance in meters between camera and target position.
/// </summary>
public static float GetDistance(Camera camera, Vector3 targetPos)
{
if (camera == null) return 0f;
return Vector3.Distance(camera.transform.position, targetPos);
}
}
}