update gizmos

This commit is contained in:
DCFApixels 2025-03-03 15:56:04 +08:00
parent bd00dea972
commit b6f9a5d25a
2 changed files with 93 additions and 48 deletions

View File

@ -1,5 +1,7 @@
//#undef DEBUG
using DCFApixels.DebugXCore;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
@ -10,6 +12,41 @@ namespace DCFApixels
{
public readonly partial struct DrawHandler
{
#region Lines
public DrawHandler Lines(ReadOnlySpan<Vector3> lines)
{
for (int i = 0, iMax = lines.Length & ~1; i < iMax;)
{
Line(lines[i++], lines[i++]);
}
return this;
}
public DrawHandler LinesStrip(ReadOnlySpan<Vector3> lines)
{
for (int i = 0, iMax = lines.Length; i < iMax;)
{
Line(lines[i], lines[i++]);
}
return this;
}
public DrawHandler Lines(List<Vector3> lines)
{
for (int i = 0, iMax = lines.Count & ~1; i < iMax;)
{
Line(lines[i++], lines[i++]);
}
return this;
}
public DrawHandler LinesStrip(List<Vector3> lines)
{
for (int i = 0, iMax = lines.Count; i < iMax;)
{
Line(lines[i], lines[i++]);
}
return this;
}
#endregion
//TODO часть функционала рейкастс перенести сюда, типа рисование линий примитивами
#region LineFade
[IN(LINE)]
@ -107,18 +144,21 @@ namespace DCFApixels
#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(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(Vector3 origin, Quaternion rotation) => Ray(origin, rotation * Vector3.forward);
[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(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(Ray ray) => RayArrow(ray.origin, ray.direction);
[IN(LINE)] public DrawHandler RayArrow(Vector3 origin, Vector3 direction) => LineArrow(origin, origin + direction);
@ -126,8 +166,14 @@ namespace DCFApixels
#region Ray custom
[IN(LINE)]
public DrawHandler Ray(Vector3 start, Vector3 direction, DebugXLine endType) => Line(start, start + direction, DebugXLine.Default, endType);
public DrawHandler Ray(Vector3 start, Vector3 direction, DebugXLine startType, DebugXLine endType) => Line(start, start + direction, startType, endType);
public DrawHandler Ray(Transform origin, Vector3 localVector, DebugXLine endType) => Ray(origin.position, origin.rotation * localVector, endType);
public DrawHandler Ray(Vector3 origin, Quaternion rotation, DebugXLine endType) => Ray(origin, rotation * Vector3.forward, endType);
public DrawHandler Ray(Ray ray, DebugXLine endType) => Ray(ray.origin, ray.direction, endType);
public DrawHandler Ray(Vector3 origin, Vector3 direction, DebugXLine endType) => Line(origin, origin + direction, DebugXLine.Default, endType);
public DrawHandler Ray(Transform origin, Vector3 localVector, DebugXLine startType, DebugXLine endType) => Ray(origin.position, origin.rotation * localVector, startType, endType);
public DrawHandler Ray(Vector3 origin, Quaternion rotation, DebugXLine startType, DebugXLine endType) => Ray(origin, rotation * Vector3.forward, startType, endType);
public DrawHandler Ray(Ray ray, DebugXLine startType, DebugXLine endType) => Ray(ray.origin, ray.direction, startType, endType);
public DrawHandler Ray(Vector3 origin, Vector3 direction, DebugXLine startType, DebugXLine endType) => Line(origin, origin + direction, startType, endType);
#endregion

View File

@ -11,6 +11,30 @@ namespace DCFApixels
private const float ShadowAlphaMultiplier = 0.3f;
public readonly partial struct DrawHandler
{
#region RaycastHit
[IN(LINE)]
public DrawHandler RaycastHit(RaycastHit hit)
{
if (hit.collider != null)
{
DotDiamond(hit.point);
RayArrow(hit.point, hit.normal);
}
return this;
}
[IN(LINE)]
public DrawHandler RaycastHit(RaycastHit2D hit)
{
if (hit.collider != null)
{
DotDiamond(hit.point);
RayArrow(hit.point, hit.normal);
}
return this;
}
#endregion
#region Raycast
[IN(LINE)] public DrawHandler Raycast(Ray ray, RaycastHit hit) => Raycast(ray.origin, ray.direction, hit);
[IN(LINE)]
@ -23,9 +47,7 @@ namespace DCFApixels
else
{
Line(origin, origin + direction * hit.distance);
DotDiamond(hit.point);
RayArrow(hit.point, hit.normal);
RaycastHit(hit);
}
return this;
}
@ -46,12 +68,10 @@ namespace DCFApixels
Vector3 end = origin + direction * hit.distance;
WidthOutLine(origin, end, radius * 2f);
DotDiamond(hit.point);
WireSphere(end, radius);
RayArrow(hit.point, hit.normal);
Setup(Color.SetAlpha(ShadowAlphaMultiplier)).Line(origin, end);
WireSphere(end, radius);
RaycastHit(hit);
}
return this;
}
@ -72,13 +92,10 @@ namespace DCFApixels
Vector3 end = origin + direction * hit.distance;
WidthOutLine(origin, end, size.x * 2f);
DotDiamond(hit.point);
WireCube(end, rotation, size * 2f);
RayArrow(hit.point, hit.normal);
Setup(Color.SetAlpha(ShadowAlphaMultiplier)).Line(origin, end);
WireCube(end, rotation, size * 2f);
RaycastHit(hit);
}
return this;
}
@ -113,13 +130,10 @@ namespace DCFApixels
Vector3 end = origin + direction * hit.distance;
WidthOutLine(origin, end, radius * 2f);
DotDiamond(hit.point);
WireCapsule(end, rotation, radius, height);
RayArrow(hit.point, hit.normal);
Setup(Color.SetAlpha(ShadowAlphaMultiplier)).Line(origin, end);
WireCapsule(end, rotation, radius, height);
RaycastHit(hit);
}
return this;
}
@ -139,8 +153,7 @@ namespace DCFApixels
{
Line(origin, origin + (Vector3)direction * hit.distance);
DotDiamond(new Vector3(hit.point.x, hit.point.y, origin.z));
RayArrow(new Vector3(hit.point.x, hit.point.y, origin.z), hit.normal);
RaycastHit(hit);
}
return this;
}
@ -161,14 +174,10 @@ namespace DCFApixels
{
Vector3 end = origin + (Vector3)direction * hit.distance;
//WidthOutLine(origin, end, radius * 2f);
DotDiamond(new Vector3(hit.point.x, hit.point.y, origin.z));
WireCircle(end, Normal2D, radius);
RayArrow(new Vector3(hit.point.x, hit.point.y, origin.z), hit.normal);
//Setup(Color.SetAlpha(ShadowAlphaMultiplier)).
Line(origin, end);
WireCircle(end, Normal2D, radius);
RaycastHit(hit);
}
return this;
}
@ -190,15 +199,10 @@ namespace DCFApixels
{
Vector3 end = origin + (Vector3)direction * hit.distance;
//WidthOutLine(origin, end, size.x * 2f);
DotDiamond(new Vector3(hit.point.x, hit.point.y, origin.z));
WireQuad(end, rotation, size * 2f);
RayArrow(new Vector3(hit.point.x, hit.point.y, origin.z), hit.normal);
//Setup(Color.SetAlpha(ShadowAlphaMultiplier)).
Line(origin, end);
WireQuad(end, rotation, size * 2f);
RaycastHit(hit);
}
return this;
}
@ -221,15 +225,10 @@ namespace DCFApixels
{
Vector3 end = origin + (Vector3)direction * hit.distance;
//WidthOutLine(origin, end, radius * 2f);
DotDiamond(new Vector3(hit.point.x, hit.point.y, origin.z));
WireFlatCapsule(end, rotation, radius, height);
RayArrow(new Vector3(hit.point.x, hit.point.y, origin.z), hit.normal);
//Setup(Color.SetAlpha(ShadowAlphaMultiplier)).
Line(origin, end);
WireFlatCapsule(end, rotation, radius, height);
RaycastHit(hit);
}
return this;
}