mirror of
https://github.com/DCFApixels/Unity-DebugX.git
synced 2025-09-18 01:54:37 +08:00
Compare commits
2 Commits
c6e1acc697
...
f7bc2def04
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7bc2def04 | ||
![]() |
3ee671aed5 |
@ -92,7 +92,7 @@ namespace DCFApixels
|
||||
{
|
||||
Mesh = mesh;
|
||||
Position = position;
|
||||
Rotation = rotation;
|
||||
Rotation = rotation.CheckQuaternionOrDefault();
|
||||
Size = size;
|
||||
}
|
||||
public IGizmoRenderer<MeshGizmo<TMat>> RegisterNewRenderer() { return new Renderer(); }
|
||||
@ -146,7 +146,7 @@ namespace DCFApixels
|
||||
public readonly Vector3 Size;
|
||||
public InstancingMeshGizmoLayout(Vector3 position, Quaternion rotation, Vector3 size)
|
||||
{
|
||||
Rotation = rotation;
|
||||
Rotation = rotation.CheckQuaternionOrDefault();
|
||||
Position = position;
|
||||
Size = size;
|
||||
}
|
||||
|
64
Runtime/Gizmos/DebugX.other.cs
Normal file
64
Runtime/Gizmos/DebugX.other.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using DCFApixels.DebugXCore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace DCFApixels
|
||||
{
|
||||
public static class WireArcGizmosExtensions
|
||||
{
|
||||
public static DebugX.DrawHandler WireArc(this DebugX.DrawHandler self, Vector3 center, Vector3 normal, Vector3 from, float angle, float radius)
|
||||
{
|
||||
return self.Gizmo(new WireArcGizmos(center, normal, from, angle, radius));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace DCFApixels.DebugXCore
|
||||
{
|
||||
using static DebugX;
|
||||
using IN = System.Runtime.CompilerServices.MethodImplAttribute;
|
||||
public struct WireArcGizmos : IGizmo<WireArcGizmos>
|
||||
{
|
||||
public readonly Vector3 Position;
|
||||
public readonly Vector3 Normal;
|
||||
public readonly Vector3 From;
|
||||
public readonly float Angle;
|
||||
public readonly float Radius;
|
||||
[IN(LINE)]
|
||||
public WireArcGizmos(Vector3 position, Vector3 normal, Vector3 from, float angle, float radius)
|
||||
{
|
||||
Position = position;
|
||||
Normal = normal.CheckNormalOrDefault();
|
||||
From = from;
|
||||
Angle = angle;
|
||||
Radius = radius;
|
||||
}
|
||||
public IGizmoRenderer<WireArcGizmos> RegisterNewRenderer()
|
||||
{
|
||||
return new Renderer();
|
||||
}
|
||||
|
||||
private class Renderer : IGizmoRenderer<WireArcGizmos>
|
||||
{
|
||||
public int ExecuteOrder => default(WireMat).GetExecuteOrder();
|
||||
public bool IsStaticRender => false;
|
||||
public void Prepare(Camera camera, GizmosList<WireArcGizmos> list) { }
|
||||
public void Render(Camera camera, GizmosList<WireArcGizmos> list, CommandBuffer cb)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Color handles_color = Handles.color;
|
||||
foreach (var gizmo in list)
|
||||
{
|
||||
Handles.color = gizmo.Color;
|
||||
Handles.DrawWireArc(gizmo.Value.Position, gizmo.Value.Normal, gizmo.Value.From, gizmo.Value.Angle, gizmo.Value.Radius);
|
||||
}
|
||||
Handles.color = handles_color;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
2
Runtime/Gizmos/DebugX.other.cs.meta
Normal file
2
Runtime/Gizmos/DebugX.other.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3f0e370bd83bef4a8955d9f9979ce01
|
@ -137,7 +137,7 @@ namespace DCFApixels
|
||||
public DrawHandler Circle<TMat>(Vector3 position, Vector3 normal, float radius)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<CircleMesh, TMat>(position, Quaternion.LookRotation(normal), new Vector3(radius, radius, radius));
|
||||
return Mesh<CircleMesh, TMat>(position, Quaternion.LookRotation(normal.CheckNormalOrDefault()), new Vector3(radius, radius, radius));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Circle<TMat>(Vector3 position, Quaternion rotation, float radius)
|
||||
@ -148,7 +148,7 @@ namespace DCFApixels
|
||||
[IN(LINE)]
|
||||
public DrawHandler Circle(Vector3 position, Vector3 normal, float radius)
|
||||
{
|
||||
return Mesh<CircleMesh>(position, Quaternion.LookRotation(normal), new Vector3(radius, radius, radius));
|
||||
return Mesh<CircleMesh>(position, Quaternion.LookRotation(normal.CheckNormalOrDefault()), new Vector3(radius, radius, radius));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Circle(Vector3 position, Quaternion rotation, float radius)
|
||||
|
@ -11,6 +11,7 @@ namespace DCFApixels
|
||||
public readonly partial struct DrawHandler
|
||||
{
|
||||
#if DEBUGX_ENABLE_PHYSICS3D
|
||||
|
||||
#region RaycastHit
|
||||
[IN(LINE)]
|
||||
public DrawHandler RaycastHit(RaycastHit hit)
|
||||
@ -130,6 +131,7 @@ namespace DCFApixels
|
||||
#endif
|
||||
|
||||
#if DEBUGX_ENABLE_PHYSICS2D
|
||||
|
||||
#region RaycastHit2D
|
||||
[IN(LINE)]
|
||||
public DrawHandler RaycastHit(RaycastHit2D hit)
|
||||
|
27
Runtime/Utils/ValidationUtils.cs
Normal file
27
Runtime/Utils/ValidationUtils.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DebugXCore
|
||||
{
|
||||
public static class ValidationUtils
|
||||
{
|
||||
public static Quaternion CheckQuaternionOrDefault(this Quaternion quaternion)
|
||||
{
|
||||
float sqrMagnitude = quaternion.x * quaternion.x + quaternion.y * quaternion.y + quaternion.z * quaternion.z + quaternion.w * quaternion.w;
|
||||
if (float.IsNaN(sqrMagnitude) || (sqrMagnitude < float.Epsilon))
|
||||
{
|
||||
return Quaternion.identity;
|
||||
}
|
||||
return quaternion;
|
||||
}
|
||||
|
||||
public static Vector3 CheckNormalOrDefault(this Vector3 normal)
|
||||
{
|
||||
float sqrMagnitude = normal.sqrMagnitude;
|
||||
if (float.IsNaN(sqrMagnitude) || (sqrMagnitude < float.Epsilon))
|
||||
{
|
||||
return Vector3.forward;
|
||||
}
|
||||
return normal;
|
||||
}
|
||||
}
|
||||
}
|
2
Runtime/Utils/ValidationUtils.cs.meta
Normal file
2
Runtime/Utils/ValidationUtils.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfcf280d995044a46b559a8da9d2f25d
|
@ -26,7 +26,7 @@ namespace DCFApixels.DebugXCore.Samples
|
||||
int i = -1;
|
||||
const float RADIUS_M = 0.5f;
|
||||
|
||||
i++; DebugX.Draw(GetColor(Points[i])).Cross(Points[i].position, Points[i].localScale.x);
|
||||
i++; DebugX.Draw(GetColor(Points[i])).BillboardCross(Points[i].position, Points[i].localScale.x);
|
||||
i++; DebugX.Draw(GetColor(Points[i])).BillboardCircle(Points[i].position, Points[i].localScale.x * RADIUS_M);
|
||||
i++; DebugX.Draw(GetColor(Points[i])).WireMesh<SphereMesh>(Points[i].position, Points[i].rotation, Points[i].localScale * RADIUS_M);
|
||||
i++; DebugX.Draw(GetColor(Points[i])).Text(Points[i].position, Points[i].name, DebugXTextSettings.WorldSpaceScale.SetSize(26).SetBackground(TextBackgroundColor));
|
||||
|
Loading…
Reference in New Issue
Block a user