public static void DrawBox2D(Vector2 origin, Vector2 size, float angle, Color color, float duration = 0) { DrawBoxStructure2D boxStructure2D = new DrawBoxStructure2D(size, angle, origin); DrawBox2DFast(Vector2.zero, boxStructure2D, DrawLine); void DrawLine(Vector3 a, Vector3 b) => lineDelegate(a, b, color, duration); }
public static void DrawBoxCast2D( Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance, Color colorStart, Color colorEnd) { direction.EnsureNormalized(); DrawBoxStructure2D boxStructure2D = new DrawBoxStructure2D(size, angle, origin); Color color = colorStart; DrawBox2DFast(Vector2.zero, boxStructure2D, DrawLine); Vector2 scaledDirection = direction * distance; float dotUR = Vector2.Dot(direction, boxStructure2D.UROrigin); float dotBL = Vector2.Dot(direction, boxStructure2D.ULOrigin); Vector2 p1; Vector2 p2; if (Mathf.Abs(dotUR) < Mathf.Abs(dotBL)) { p1 = boxStructure2D.UR; p2 = boxStructure2D.BL; } else { p1 = boxStructure2D.UL; p2 = boxStructure2D.BR; } Vector2 originA = p1; Vector2 originB = p2; Vector2 currentA = originA; Vector2 currentB = originB; for (int i = 1; i <= 10; i++) { float t = i / (float)10; color = Color.Lerp(colorStart, colorEnd, t); Vector2 nextA = originA + scaledDirection * t; Vector2 nextB = originB + scaledDirection * t; DrawLine(currentA, nextA); DrawLine(currentB, nextB); currentA = nextA; currentB = nextB; } color = colorEnd; DrawBox2DFast(scaledDirection, boxStructure2D, DrawLine); void DrawLine(Vector3 a, Vector3 b) => lineDelegate(a, b, color); }
internal static void DrawBox2DFast( Vector2 offset, DrawBoxStructure2D boxStructure2D, LineDelegateSimple lineDelegate) { Vector2 uRPosition = offset + boxStructure2D.UR; Vector2 uLPosition = offset + boxStructure2D.UL; Vector2 bRPosition = offset + boxStructure2D.BR; Vector2 bLPosition = offset + boxStructure2D.BL; lineDelegate(uLPosition, uRPosition); lineDelegate(uRPosition, bRPosition); lineDelegate(bRPosition, bLPosition); lineDelegate(bLPosition, uLPosition); }
public static void DrawBoxCast2DHits(RaycastHit2D[] hits, Vector2 origin, Vector2 size, float angle, Vector2 direction, Color color, int maxCount = -1) { if (maxCount < 0) { maxCount = hits.Length; } if (maxCount == 0) { return; } direction.EnsureNormalized(); DrawBoxStructure2D boxStructure2D = new DrawBoxStructure2D(size, angle, origin); for (int i = 0; i < maxCount; i++) { DrawBox2DFast(direction * hits[i].distance, boxStructure2D, DrawLine); } void DrawLine(Vector3 a, Vector3 b) => lineDelegate(a, b, color); }