mirror of
https://github.com/DCFApixels/Unity-DebugX.git
synced 2025-09-18 01:54:37 +08:00
update
This commit is contained in:
parent
7672285a03
commit
7029d52d3b
@ -31,26 +31,6 @@ namespace DCFApixels
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Raycast2D
|
|
||||||
//[IN(LINE)] public DrawHandler Raycast2D(Ray ray, RaycastHit hit) => Raycast(ray.origin, ray.direction, hit);
|
|
||||||
[IN(LINE)]
|
|
||||||
public DrawHandler Raycast2D(Vector2 origin, Vector2 direction, RaycastHit2D hit)
|
|
||||||
{
|
|
||||||
if (hit.collider == null)
|
|
||||||
{
|
|
||||||
RayFade(origin, direction * 3f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Line(origin, origin + direction * hit.distance);
|
|
||||||
|
|
||||||
DotDiamond(hit.point);
|
|
||||||
RayArrow(hit.point, hit.normal);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region SphereCast
|
#region SphereCast
|
||||||
[IN(LINE)] public DrawHandler SphereCast(Ray ray, float radius, RaycastHit hit) => SphereCast(ray.origin, ray.direction, radius, hit);
|
[IN(LINE)] public DrawHandler SphereCast(Ray ray, float radius, RaycastHit hit) => SphereCast(ray.origin, ray.direction, radius, hit);
|
||||||
[IN(LINE)]
|
[IN(LINE)]
|
||||||
@ -144,6 +124,116 @@ namespace DCFApixels
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Raycast2D
|
||||||
|
[IN(LINE)] public DrawHandler Raycast2D(Ray ray, RaycastHit2D hit) => Raycast2D(ray.origin, ray.direction, hit);
|
||||||
|
[IN(LINE)]
|
||||||
|
public DrawHandler Raycast2D(Vector2 origin, Vector2 direction, RaycastHit2D hit)
|
||||||
|
{
|
||||||
|
if (hit.collider == null)
|
||||||
|
{
|
||||||
|
RayFade(origin, direction * 3f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Line(origin, origin + direction * hit.distance);
|
||||||
|
|
||||||
|
DotDiamond(hit.point);
|
||||||
|
RayArrow(hit.point, hit.normal);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region CircleCast2D
|
||||||
|
private static readonly Vector3 Normal2D = Vector3.forward;
|
||||||
|
[IN(LINE)] public DrawHandler CircleCast2D(Ray ray, float radius, RaycastHit2D hit) => CircleCast2D(ray.origin, ray.direction, radius, hit);
|
||||||
|
[IN(LINE)]
|
||||||
|
public DrawHandler CircleCast2D(Vector2 origin, Vector2 direction, float radius, RaycastHit2D hit)
|
||||||
|
{
|
||||||
|
WireCircle(origin, Normal2D, radius);
|
||||||
|
if (hit.collider == null)
|
||||||
|
{
|
||||||
|
RayFade(origin, direction * 3f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Vector2 end = origin + direction * hit.distance;
|
||||||
|
|
||||||
|
//WidthOutLine(origin, end, radius * 2f);
|
||||||
|
|
||||||
|
DotDiamond(hit.point);
|
||||||
|
WireCircle(end, Normal2D, radius);
|
||||||
|
RayArrow(hit.point, hit.normal);
|
||||||
|
|
||||||
|
//Setup(Color.SetAlpha(ShadowAlphaMultiplier)).
|
||||||
|
Line(origin, end);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region BoxCast2D
|
||||||
|
[IN(LINE)] public DrawHandler BoxCast2D(Ray ray, float angle, Vector3 size, RaycastHit2D hit) => BoxCast2D(ray.origin, ray.direction, angle, size, hit);
|
||||||
|
[IN(LINE)]
|
||||||
|
public DrawHandler BoxCast2D(Vector2 origin, Vector2 direction, float angle, Vector3 size, RaycastHit2D hit)
|
||||||
|
{
|
||||||
|
size *= 0.5f;
|
||||||
|
Quaternion rotation = Quaternion.Euler(0, 0, angle);
|
||||||
|
WireQuad(origin, rotation, size * 2f);
|
||||||
|
if (hit.collider == null)
|
||||||
|
{
|
||||||
|
RayFade(origin, direction * 3f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Vector3 end = origin + direction * hit.distance;
|
||||||
|
|
||||||
|
//WidthOutLine(origin, end, size.x * 2f);
|
||||||
|
|
||||||
|
DotDiamond(hit.point);
|
||||||
|
WireQuad(end, rotation, size * 2f);
|
||||||
|
RayArrow(hit.point, hit.normal);
|
||||||
|
|
||||||
|
|
||||||
|
//Setup(Color.SetAlpha(ShadowAlphaMultiplier)).
|
||||||
|
Line(origin, end);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region CapsuleCast2D
|
||||||
|
[IN(LINE)] public DrawHandler CapsuleCast2D(Ray ray, float angle, Vector2 size, CapsuleDirection2D capsuleDirection, RaycastHit2D hit) => CapsuleCast2D(ray.origin, ray.direction, angle, size, capsuleDirection, hit);
|
||||||
|
[IN(LINE)]
|
||||||
|
public DrawHandler CapsuleCast2D(Vector2 origin, Vector2 direction, float angle, Vector2 size, CapsuleDirection2D capsuleDirection, RaycastHit2D hit)
|
||||||
|
{
|
||||||
|
var rotation = Quaternion.Euler(0, 0, angle);
|
||||||
|
var height = (capsuleDirection == CapsuleDirection2D.Vertical ? size.y : size.x);
|
||||||
|
var radius = (capsuleDirection == CapsuleDirection2D.Vertical ? size.x : size.y) * 0.5f;
|
||||||
|
WireFlatCapsule(origin, rotation, radius, height);
|
||||||
|
if (hit.collider == null)
|
||||||
|
{
|
||||||
|
RayFade(origin, direction * 3f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Vector3 end = origin + direction * hit.distance;
|
||||||
|
|
||||||
|
//WidthOutLine(origin, end, radius * 2f);
|
||||||
|
|
||||||
|
DotDiamond(hit.point);
|
||||||
|
WireFlatCapsule(end, rotation, radius, height);
|
||||||
|
RayArrow(hit.point, hit.normal);
|
||||||
|
|
||||||
|
|
||||||
|
//Setup(Color.SetAlpha(ShadowAlphaMultiplier)).
|
||||||
|
Line(origin, end);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -142,7 +142,7 @@ Material:
|
|||||||
- _QueueOffset: 0
|
- _QueueOffset: 0
|
||||||
- _ReceiveShadows: 0
|
- _ReceiveShadows: 0
|
||||||
- _Shininess: 0
|
- _Shininess: 0
|
||||||
- _Smoothness: 0.5
|
- _Smoothness: 0
|
||||||
- _SmoothnessSource: 0
|
- _SmoothnessSource: 0
|
||||||
- _SmoothnessTextureChannel: 0
|
- _SmoothnessTextureChannel: 0
|
||||||
- _SoftParticlesEnabled: 0
|
- _SoftParticlesEnabled: 0
|
||||||
@ -157,9 +157,9 @@ Material:
|
|||||||
- _WorkflowMode: 1
|
- _WorkflowMode: 1
|
||||||
- _ZWrite: 1
|
- _ZWrite: 1
|
||||||
m_Colors:
|
m_Colors:
|
||||||
- _BaseColor: {r: 0.5568628, g: 0.13333331, b: 0.34645054, a: 0.23529412}
|
- _BaseColor: {r: 0, g: 0.019443978, b: 0.047169805, a: 0.23529412}
|
||||||
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
|
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
|
||||||
- _Color: {r: 0.5568628, g: 0.13333327, b: 0.3464505, a: 0.23529412}
|
- _Color: {r: 0, g: 0.019443978, b: 0.047169782, a: 0.23529412}
|
||||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||||
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
@ -158,7 +158,7 @@ Material:
|
|||||||
m_Colors:
|
m_Colors:
|
||||||
- _BaseColor: {r: 0.29222006, g: 0.20719118, b: 0.4528302, a: 1}
|
- _BaseColor: {r: 0.29222006, g: 0.20719118, b: 0.4528302, a: 1}
|
||||||
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
|
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
|
||||||
- _Color: {r: 0.12668991, g: 0.03800285, b: 0.13207549, a: 1}
|
- _Color: {r: 0.0327363, g: 0.031372547, b: 0.13333334, a: 1}
|
||||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||||
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
@ -142,7 +142,7 @@ Material:
|
|||||||
- _QueueOffset: 0
|
- _QueueOffset: 0
|
||||||
- _ReceiveShadows: 0
|
- _ReceiveShadows: 0
|
||||||
- _Shininess: 0
|
- _Shininess: 0
|
||||||
- _Smoothness: 0.5
|
- _Smoothness: 0
|
||||||
- _SmoothnessSource: 0
|
- _SmoothnessSource: 0
|
||||||
- _SmoothnessTextureChannel: 0
|
- _SmoothnessTextureChannel: 0
|
||||||
- _SoftParticlesEnabled: 0
|
- _SoftParticlesEnabled: 0
|
||||||
@ -157,9 +157,9 @@ Material:
|
|||||||
- _WorkflowMode: 1
|
- _WorkflowMode: 1
|
||||||
- _ZWrite: 1
|
- _ZWrite: 1
|
||||||
m_Colors:
|
m_Colors:
|
||||||
- _BaseColor: {r: 0.3584906, g: 0.038892854, b: 0.21198066, a: 0.23529412}
|
- _BaseColor: {r: 0.21332264, g: 0.12896049, b: 0.4339623, a: 0.23529412}
|
||||||
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
|
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
|
||||||
- _Color: {r: 0.35849056, g: 0.038892854, b: 0.21198061, a: 0.23529412}
|
- _Color: {r: 0.21332261, g: 0.12896046, b: 0.43396226, a: 0.23529412}
|
||||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
- _Flip: {r: 1, g: 1, b: 1, a: 1}
|
||||||
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
1052
Samples/Sample.unity
1052
Samples/Sample.unity
File diff suppressed because it is too large
Load Diff
52
Samples/Scripts/DebugXSample_Raycasts2D.cs
Normal file
52
Samples/Scripts/DebugXSample_Raycasts2D.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DCFApixels
|
||||||
|
{
|
||||||
|
public class DebugXSample_Raycasts2D : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Gradient Gradient;
|
||||||
|
public float GradientMultiplier = 5;
|
||||||
|
public Transform[] Points;
|
||||||
|
|
||||||
|
private void OnDrawGizmos()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
const float RADIUS_M = 0.5f;
|
||||||
|
|
||||||
|
Transform point;
|
||||||
|
Ray ray;
|
||||||
|
RaycastHit2D hit;
|
||||||
|
|
||||||
|
point = Points[i++];
|
||||||
|
ray = new Ray(point.position, point.forward);
|
||||||
|
hit = Physics2D.Raycast(ray.origin, ray.direction, float.PositiveInfinity, -1);
|
||||||
|
DebugX.Draw(GetColor(point)).Raycast2D(ray, hit);
|
||||||
|
|
||||||
|
point = Points[i++];
|
||||||
|
ray = new Ray(point.position, point.forward);
|
||||||
|
hit = Physics2D.CircleCast(ray.origin, point.localScale.x * RADIUS_M, ray.direction, float.PositiveInfinity, int.MaxValue);
|
||||||
|
DebugX.Draw(GetColor(point)).CircleCast2D(ray, point.localScale.x * RADIUS_M, hit);
|
||||||
|
|
||||||
|
point = Points[i++];
|
||||||
|
ray = new Ray(point.position, point.forward);
|
||||||
|
hit = Physics2D.BoxCast(ray.origin, point.localScale, point.eulerAngles.z, ray.direction, float.PositiveInfinity, int.MaxValue);
|
||||||
|
DebugX.Draw(GetColor(point)).BoxCast2D(ray, point.eulerAngles.z, point.localScale, hit);
|
||||||
|
|
||||||
|
point = Points[i++];
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
private Color GetColor(Transform pos1)
|
||||||
|
{
|
||||||
|
Vector3 pos = pos1.localPosition;
|
||||||
|
pos /= GradientMultiplier == 0 ? 1 : GradientMultiplier;
|
||||||
|
pos += Vector3.one * 0.5f;
|
||||||
|
//float t = pos.x + pos.y + pos.z;
|
||||||
|
//t /= 3f;
|
||||||
|
float t = pos.x + pos.z;
|
||||||
|
t /= 2f;
|
||||||
|
return Gradient.Evaluate(Mathf.Clamp01(t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
Samples/Scripts/DebugXSample_Raycasts2D.cs.meta
Normal file
2
Samples/Scripts/DebugXSample_Raycasts2D.cs.meta
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0eb828199b6984f45a508878c98fb48a
|
@ -2,7 +2,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace DCFApixels
|
namespace DCFApixels
|
||||||
{
|
{
|
||||||
public class DebugXSample_Raycasts : MonoBehaviour
|
public class DebugXSample_Raycasts3D : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Gradient Gradient;
|
public Gradient Gradient;
|
||||||
public float GradientMultiplier = 5;
|
public float GradientMultiplier = 5;
|
Loading…
Reference in New Issue
Block a user