mirror of
https://github.com/DCFApixels/Unity-DebugX.git
synced 2025-09-19 02:24:36 +08:00
add new lines/rays
This commit is contained in:
parent
9695037e09
commit
862d86733d
@ -1,4 +1,5 @@
|
||||
using DCFApixels.DebugXCore;
|
||||
using DCFApixels.DebugXCore.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -263,24 +264,65 @@ namespace DCFApixels
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Line primitives
|
||||
[IN(LINE)]
|
||||
public DrawHandler LineWireBox(Vector3 start, Vector3 end, Quaternion rotation, Vector3 size)
|
||||
{
|
||||
size *= 2f;
|
||||
WidthOutLine(start, end, size.x);
|
||||
WireCube(start, rotation, size);
|
||||
WireCube(end, rotation, size);
|
||||
Setup(Color.SetAlpha(ShadowAlphaMultiplier)).Line(start, end);
|
||||
return this;
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler LineWireSphere(Vector3 start, Vector3 end, float radius)
|
||||
{
|
||||
WidthOutLine(start, end, radius * 2f);
|
||||
WireSphere(start, radius);
|
||||
WireSphere(end, radius);
|
||||
Setup(Color.SetAlpha(ShadowAlphaMultiplier)).Line(start, end);
|
||||
return this;
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler LineWireCapsule(Vector3 startPoint1, Vector3 startPoint2, Vector3 end, float radius) => LineWireCapsule_Internal(startPoint1, startPoint1, (startPoint1 + startPoint2) * 0.5f, end, radius);
|
||||
[IN(LINE)]
|
||||
private DrawHandler LineWireCapsule_Internal(Vector3 startPoint1, Vector3 startPoint2, Vector3 startCenter, Vector3 end, float radius)
|
||||
{
|
||||
Quaternion rotation = Quaternion.LookRotation(startPoint2 - startPoint1, Vector3.up);
|
||||
rotation = rotation * Quaternion.Euler(90, 0, 0);
|
||||
LineWireCapsule(startCenter, end, rotation, radius, Vector3.Distance(startPoint1, startPoint2) + radius * 2f);
|
||||
return this;
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler LineWireCapsule(Vector3 start, Vector3 end, Quaternion rotation, float radius, float height)
|
||||
{
|
||||
WidthOutLine(start, end, radius * 2f);
|
||||
WireCapsule(start, rotation, radius, height);
|
||||
WireCapsule(end, rotation, radius, height);
|
||||
Setup(Color.SetAlpha(ShadowAlphaMultiplier)).Line(start, end);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Ray
|
||||
[IN(LINE)] public DrawHandler Ray(Transform origin, Vector3 localVector) => Ray(origin.position, origin.rotation * localVector);
|
||||
[IN(LINE)] public DrawHandler Ray(Vector3 origin, Quaternion rotation) => Ray(origin, rotation * Vector3.forward);
|
||||
[IN(LINE)] public DrawHandler Ray(Transform transform, Vector3 localVector) => Ray(transform.position, transform.rotation * localVector);
|
||||
[IN(LINE)] public DrawHandler Ray(Vector3 origin, Quaternion direction) => Ray(origin, direction * Vector3.forward);
|
||||
[IN(LINE)] public DrawHandler Ray(Ray ray) => Ray(ray.origin, ray.direction);
|
||||
[IN(LINE)] public DrawHandler Ray(Vector3 origin, Vector3 direction) => Line(origin, origin + direction);
|
||||
#endregion
|
||||
|
||||
#region RayFade
|
||||
[IN(LINE)] public DrawHandler RayFade(Transform origin, Vector3 localVector) => RayFade(origin.position, origin.rotation * localVector);
|
||||
[IN(LINE)] public DrawHandler RayFade(Vector3 origin, Quaternion rotation) => RayFade(origin, rotation * Vector3.forward);
|
||||
[IN(LINE)] public DrawHandler RayFade(Transform transform, Vector3 localVector) => RayFade(transform.position, transform.rotation * localVector);
|
||||
[IN(LINE)] public DrawHandler RayFade(Vector3 origin, Quaternion direction) => RayFade(origin, direction * Vector3.forward);
|
||||
[IN(LINE)] public DrawHandler RayFade(Ray ray) => RayFade(ray.origin, ray.direction);
|
||||
[IN(LINE)] public DrawHandler RayFade(Vector3 origin, Vector3 direction) => LineFade(origin, origin + direction);
|
||||
#endregion
|
||||
|
||||
#region RayArrow
|
||||
[IN(LINE)] public DrawHandler RayArrow(Transform origin, Vector3 localVector) => RayArrow(origin.position, origin.rotation * localVector);
|
||||
[IN(LINE)] public DrawHandler RayArrow(Vector3 origin, Quaternion rotation) => RayArrow(origin, rotation * Vector3.forward);
|
||||
[IN(LINE)] public DrawHandler RayArrow(Transform transform, Vector3 localVector) => RayArrow(transform.position, transform.rotation * localVector);
|
||||
[IN(LINE)] public DrawHandler RayArrow(Vector3 origin, Quaternion direction) => RayArrow(origin, direction * Vector3.forward);
|
||||
[IN(LINE)] public DrawHandler RayArrow(Ray ray) => RayArrow(ray.origin, ray.direction);
|
||||
[IN(LINE)] public DrawHandler RayArrow(Vector3 origin, Vector3 direction) => LineArrow(origin, origin + direction);
|
||||
#endregion
|
||||
@ -297,6 +339,37 @@ namespace DCFApixels
|
||||
public DrawHandler Ray(Vector3 origin, Vector3 direction, DebugXLine startType, DebugXLine endType) => Line(origin, origin + direction, startType, endType);
|
||||
#endregion
|
||||
|
||||
#region Ray primitives
|
||||
[IN(LINE)] public DrawHandler RayWireBox(Transform transform, Vector3 localVector, Quaternion rotation, Vector3 size) => RayWireBox(transform.position, transform.rotation * localVector, transform.rotation * rotation, transform.lossyScale.Mult(size));
|
||||
[IN(LINE)] public DrawHandler RayWireBox(Vector3 origin, Quaternion direction, Quaternion rotation, Vector3 size) => RayWireBox(origin, direction * Vector3.forward, rotation, size);
|
||||
[IN(LINE)] public DrawHandler RayWireBox(Ray ray, Quaternion rotation, Vector3 size) => RayWireBox(ray.origin, ray.direction, rotation, size);
|
||||
[IN(LINE)] public DrawHandler RayWireBox(Vector3 origin, Vector3 direction, Quaternion rotation, Vector3 size) => LineWireBox(origin, origin + direction, rotation, size);
|
||||
|
||||
[IN(LINE)] public DrawHandler RayWireSphere(Transform transform, Vector3 localVector, float radius) => RayWireSphere(transform.position, transform.rotation * localVector, radius);
|
||||
[IN(LINE)] public DrawHandler RayWireSphere(Vector3 origin, Quaternion direction, float radius) => RayWireSphere(origin, direction * Vector3.forward, radius);
|
||||
[IN(LINE)] public DrawHandler RayWireSphere(Ray ray, float radius) => RayWireSphere(ray.origin, ray.direction, radius);
|
||||
[IN(LINE)] public DrawHandler RayWireSphere(Vector3 origin, Vector3 direction, float radius) => LineWireSphere(origin, origin + direction, radius);
|
||||
|
||||
|
||||
[IN(LINE)] public DrawHandler RayWireCapsule(Vector3 startPoint1, Vector3 startPoint2, Quaternion direction, float radius) => RayWireCapsule(startPoint1, startPoint2, direction * Vector3.forward, radius);
|
||||
[IN(LINE)]
|
||||
public DrawHandler RayWireCapsule(Vector3 startPoint1, Vector3 startPoint2, Vector3 direction, float radius)
|
||||
{
|
||||
var center = (startPoint1 + startPoint2) * 0.5f;
|
||||
return LineWireCapsule_Internal(startPoint1, startPoint1, center, center + direction, radius);
|
||||
}
|
||||
|
||||
[IN(LINE)]
|
||||
public DrawHandler RayWireCapsule(Transform transform, Vector3 localVector, Quaternion rotation, float radius, float height)
|
||||
{
|
||||
var scale = transform.lossyScale;
|
||||
return RayWireCapsule(transform.position, transform.rotation * localVector, transform.rotation * rotation, radius + scale.x, height * scale.y);
|
||||
}
|
||||
[IN(LINE)] public DrawHandler RayWireCapsule(Vector3 origin, Quaternion direction, Quaternion rotation, float radius, float height) => RayWireCapsule(origin, direction * Vector3.forward, rotation, radius, height);
|
||||
[IN(LINE)] public DrawHandler RayWireCapsule(Ray ray, Quaternion rotation, float radius, float height) => RayWireCapsule(ray.origin, ray.direction, rotation, radius, height);
|
||||
[IN(LINE)] public DrawHandler RayWireCapsule(Vector3 origin, Vector3 direction, Quaternion rotation, float radius, float height) => LineWireCapsule(origin, origin + direction, rotation, radius, height);
|
||||
#endregion
|
||||
|
||||
|
||||
#region WidthLine
|
||||
[IN(LINE)] public DrawHandler WidthLine(Vector3 start, Vector3 end, float width) => Gizmo(new WidthLineGizmo(start, end, width));
|
||||
|
@ -72,7 +72,8 @@ namespace DCFApixels
|
||||
[IN(LINE)]
|
||||
public DrawHandler BoxCast(Vector3 origin, Vector3 direction, Quaternion rotation, Vector3 size, RaycastHit hit)
|
||||
{
|
||||
WireCube(origin, rotation, size * 2f);
|
||||
size *= 2f;
|
||||
WireCube(origin, rotation, size);
|
||||
if (hit.collider == null)
|
||||
{
|
||||
RayFade(origin, direction * 3f);
|
||||
@ -81,9 +82,9 @@ namespace DCFApixels
|
||||
{
|
||||
Vector3 end = origin + direction * hit.distance;
|
||||
|
||||
WidthOutLine(origin, end, size.x * 2f);
|
||||
WidthOutLine(origin, end, size.x);
|
||||
Setup(Color.SetAlpha(ShadowAlphaMultiplier)).Line(origin, end);
|
||||
WireCube(end, rotation, size * 2f);
|
||||
WireCube(end, rotation, size);
|
||||
|
||||
RaycastHit(hit);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
using DCFApixels.DebugXCore;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
//#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
//#endif
|
||||
|
||||
namespace DCFApixels
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace DCFApixels.DebugXCore.Internal
|
||||
{
|
||||
internal static class ColorExtensions
|
||||
internal static class Extensions
|
||||
{
|
||||
public static Color SetAlpha(this Color self, float v)
|
||||
{
|
||||
@ -14,5 +14,18 @@ namespace DCFApixels.DebugXCore.Internal
|
||||
self.color.a *= self.alpha;
|
||||
return self.color;
|
||||
}
|
||||
public static Vector3 Mult(this Vector3 a, Vector3 b)
|
||||
{
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
a.z *= b.z;
|
||||
return a;
|
||||
}
|
||||
public static Vector2 Mult(this Vector2 a, Vector2 b)
|
||||
{
|
||||
a.x *= b.x;
|
||||
a.y *= b.y;
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ namespace DCFApixels.DebugXCore.Samples
|
||||
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));
|
||||
|
||||
|
||||
i++; DebugX.Draw(GetColor(Points[i])).Dot(Points[i].position);
|
||||
i++; DebugX.Draw(GetColor(Points[i])).WireDot(Points[i].position);
|
||||
i++; DebugX.Draw(GetColor(Points[i])).DotQuad(Points[i].position);
|
||||
|
Loading…
Reference in New Issue
Block a user