From af2a55e2c8b2321194fbf2b74eaad96367943f52 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 5 Mar 2025 16:19:16 +0800 Subject: [PATCH] add 2d lines --- Runtime/Gizmos/DebugX.lines.cs | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/Runtime/Gizmos/DebugX.lines.cs b/Runtime/Gizmos/DebugX.lines.cs index 69a05b2..f3f02ad 100644 --- a/Runtime/Gizmos/DebugX.lines.cs +++ b/Runtime/Gizmos/DebugX.lines.cs @@ -90,6 +90,85 @@ namespace DCFApixels } #endregion + #region Lines2D + [IN(LINE)] public DrawHandler Lines(Vector2[] points) => Lines(new ReadOnlySpan(points)); + [IN(LINE)] public DrawHandler Lines(Vector2[] points, int length) => Lines(new ReadOnlySpan(points, 0, length)); + [IN(LINE)] public DrawHandler Lines(Vector2[] points, int startIndex, int length) => Lines(new ReadOnlySpan(points, startIndex, length)); + [IN(LINE)] + public DrawHandler Lines(ReadOnlySpan points) + { + for (int i = 0, iMax = points.Length & ~1; i < iMax;) + { + Line(points[i++], points[i++]); + } + return this; + } + [IN(LINE)] public DrawHandler Lines(List points) => Lines(points, 0, points.Count); + [IN(LINE)] public DrawHandler Lines(List points, int length) => Lines(points, 0, length); + [IN(LINE)] + public DrawHandler Lines(List points, int startIndex, int length) + { + for (int i = startIndex, iMax = startIndex + (length & ~1); i < iMax;) + { + Line(points[i++], points[i++]); + } + return this; + } + public DrawHandler Lines(IEnumerable points) + { + var enumerator = points.GetEnumerator(); + while (true) + { + if (enumerator.MoveNext() == false) { break; } + Vector3 startPoint = enumerator.Current; + if (enumerator.MoveNext() == false) { break; } + Vector3 endPoint = enumerator.Current; + Line(startPoint, endPoint); + } + return this; + } + #endregion + + #region LineStrip2D + [IN(LINE)] public DrawHandler LineStrip(Vector2[] points) => LineStrip(new ReadOnlySpan(points)); + [IN(LINE)] public DrawHandler LineStrip(Vector2[] points, int length) => LineStrip(new ReadOnlySpan(points, 0, length)); + [IN(LINE)] public DrawHandler LineStrip(Vector2[] points, int startIndex, int length) => LineStrip(new ReadOnlySpan(points, startIndex, length)); + [IN(LINE)] + public DrawHandler LineStrip(ReadOnlySpan points) + { + for (int i = 0, iMax = points.Length - 1; i < iMax;) + { + Line(points[i], points[++i]); + } + return this; + } + [IN(LINE)] public DrawHandler LineStrip(List points) => LineStrip(points, 0, points.Count); + [IN(LINE)] public DrawHandler LineStrip(List points, int length) => LineStrip(points, 0, length); + [IN(LINE)] + public DrawHandler LineStrip(List points, int startIndex, int length) + { + for (int i = startIndex, iMax = startIndex + length; i < iMax;) + { + Line(points[i], points[++i]); + } + return this; + } + public DrawHandler LineStrip(IEnumerable points) + { + var enumerator = points.GetEnumerator(); + enumerator.MoveNext(); + Vector3 startPoint = enumerator.Current; + while (enumerator.MoveNext()) + { + Vector3 endPoint = enumerator.Current; + Line(startPoint, endPoint); + startPoint = endPoint; + } + return this; + } + #endregion + + //TODO часть функционала рейкастс перенести сюда, типа рисование линий примитивами #region LineFade [IN(LINE)]