add defines for physics

This commit is contained in:
DCFApixels 2025-03-12 21:49:38 +08:00
parent 45d3885aa2
commit 90e44311d3
5 changed files with 43 additions and 20 deletions

View File

@ -25,7 +25,7 @@ namespace DCFApixels.DebugXCore.Internal
private static bool _isCompilation;
private bool? _isHasDisableDebugXInBuildSymbols = false;
private const string DEFINE_NAME = nameof(DebugXDefines.DISABLE_DEBUGX_INBUILD);
private const string DEFINE_NAME = nameof(DebugXDefines.DEBUGX_DISABLE_INBUILD);
private void OnGUI()
{

View File

@ -47,7 +47,19 @@ namespace DCFApixels.DebugXCore
{
public static class DebugXDefines
{
public const bool DISABLE_DEBUGX_INBUILD =
public const bool DEBUGX_DISABLE_INBUILD =
#if DISABLE_DEBUGX_INBUILD
true;
#else
false;
#endif
public const bool DEBUGX_ENABLE_PHYSICS2D =
#if DISABLE_DEBUGX_INBUILD
true;
#else
false;
#endif
public const bool DEBUGX_ENABLE_PHYSICS3D =
#if DISABLE_DEBUGX_INBUILD
true;
#else

View File

@ -10,6 +10,7 @@ namespace DCFApixels
private const float ShadowAlphaMultiplier = 0.3f;
public readonly partial struct DrawHandler
{
#if DEBUGX_ENABLE_PHYSICS3D
#region RaycastHit
[IN(LINE)]
public DrawHandler RaycastHit(RaycastHit hit)
@ -21,25 +22,8 @@ namespace DCFApixels
}
return this;
}
[IN(LINE)]
public DrawHandler RaycastHit(RaycastHit2D hit)
{
if (hit.collider != null)
{
DotDiamond(hit.point);
RayArrow(hit.point, hit.normal);
}
return this;
}
[IN(LINE)]
private void RaycastHit_Internal(float offsetZ, RaycastHit2D hit)
{
DotDiamond(new Vector3(hit.point.x, hit.point.y, offsetZ));
RayArrow(new Vector3(hit.point.x, hit.point.y, offsetZ), hit.normal);
}
#endregion
#region Raycast
[IN(LINE)] public DrawHandler Raycast(Ray ray, RaycastHit hit) => Raycast(ray.origin, ray.direction, hit);
[IN(LINE)]
@ -143,7 +127,27 @@ namespace DCFApixels
return this;
}
#endregion
#endif
#if DEBUGX_ENABLE_PHYSICS2D
#region RaycastHit2D
[IN(LINE)]
public DrawHandler RaycastHit(RaycastHit2D hit)
{
if (hit.collider != null)
{
DotDiamond(hit.point);
RayArrow(hit.point, hit.normal);
}
return this;
}
[IN(LINE)]
private void RaycastHit_Internal(float offsetZ, RaycastHit2D hit)
{
DotDiamond(new Vector3(hit.point.x, hit.point.y, offsetZ));
RayArrow(new Vector3(hit.point.x, hit.point.y, offsetZ), hit.normal);
}
#endregion
#region Raycast2D
[IN(LINE)] public DrawHandler Raycast2D(Ray ray, RaycastHit2D hit) => Raycast2D(ray.origin, ray.direction, hit);
@ -238,6 +242,7 @@ namespace DCFApixels
return this;
}
#endregion
#endif
}
}
}

View File

@ -23,6 +23,7 @@ namespace DCFApixels.DebugXCore.Samples
private void Draw()
{
#if DEBUGX_ENABLE_PHYSICS2D
int i = 0;
const float RADIUS_M = 0.5f;
@ -49,6 +50,7 @@ namespace DCFApixels.DebugXCore.Samples
ray = new Ray(point.position, point.forward);
hit = Physics2D.CapsuleCast(ray.origin, point.localScale, CapsuleDirection2D.Vertical, point.eulerAngles.z, ray.direction, float.PositiveInfinity, int.MaxValue);
DebugX.Draw(GetColor(point)).CapsuleCast2D(ray, point.eulerAngles.z, point.localScale, CapsuleDirection2D.Vertical, hit);
#endif
}
private Color GetColor(Transform pos1)
{

View File

@ -9,6 +9,8 @@ namespace DCFApixels.DebugXCore.Samples
public float GradientMultiplier = 5;
public Transform[] Points;
#if UNITY_EDITOR
private void OnDrawGizmos()
{
@ -23,6 +25,7 @@ namespace DCFApixels.DebugXCore.Samples
private void Draw()
{
#if DEBUGX_ENABLE_PHYSICS3D
int i = 0;
const float RADIUS_M = 0.5f;
@ -51,6 +54,7 @@ namespace DCFApixels.DebugXCore.Samples
Vector3 point2 = ray.origin + point.up * point.localScale.y * RADIUS_M * -0.5f;
Physics.CapsuleCast(point1, point2, point.localScale.x * RADIUS_M, ray.direction, out hit, float.PositiveInfinity, int.MaxValue, QueryTriggerInteraction.UseGlobal);
DebugX.Draw(GetColor(point)).CapsuleCast(point1, point2, ray.direction, point.localScale.x * RADIUS_M, hit);
#endif
}
private Color GetColor(Transform pos1)
{