diff --git a/EXILED/Exiled.API/Features/Draw.cs b/EXILED/Exiled.API/Features/Draw.cs new file mode 100644 index 000000000..07de5bbca --- /dev/null +++ b/EXILED/Exiled.API/Features/Draw.cs @@ -0,0 +1,134 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) ExMod Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.API.Features +{ + using DrawableLine; + + using Mirror; + + using UnityEngine; + + /// + /// A utility class for drawing debug lines, shapes, and bounds for players or globally. + /// + public static class Draw + { + private const float DefaultDuration = 5f; + + private static readonly Color DefaultColor = Color.green; + + /// + /// Draws a line between two specified points. + /// + /// The starting position of the line. + /// The ending position of the line. + /// The to show the line to. If , it is shown to all players. + /// The color of the line. Defaults to . + /// How long the line should remain visible. + public static void Line(Vector3 start, Vector3 end, Player player = null, Color? color = null, float duration = DefaultDuration) + { + Send(player, duration, color ?? DefaultColor, start, end); + } + + /// + /// Draws a connected path through a series of points. + /// + /// An array of points to connect sequentially. + /// The to show the path to. If , it is shown to all players. + /// The color of the path. Defaults to . + /// How long the path should remain visible. + public static void Path(Vector3[] points, Player player = null, Color? color = null, float duration = DefaultDuration) + { + Send(player, duration, color ?? DefaultColor, points); + } + + /// + /// Draws a circle at a specific position. + /// + /// The center point of the circle. + /// The radius of the circle. + /// The to show the circle to. If , it is shown to all players. + /// Indicates whether the circle should be drawn on the horizontal plane (XZ) or vertical plane (XY). + /// The number of line segments used to draw the circle. Higher values result in a smoother circle. + /// The color of the circle. Defaults to . + /// How long the circle should remain visible. + public static void Circle(Vector3 origin, float radius, Player player = null, bool horizontal = true, int segments = 16, Color? color = null, float duration = DefaultDuration) + { + Vector3[] circlePoints = DrawableLines.GetCircle(origin, radius, horizontal, segments); + Send(player, duration, color ?? DefaultColor, circlePoints); + } + + /// + /// Draws a wireframe sphere composed of two circles (horizontal and vertical). + /// + /// The center point of the sphere. + /// The radius of the sphere. + /// The to show the sphere to. If , it is shown to all players. + /// The number of segments for the circles. Higher values result in a smoother sphere. + /// The color of the sphere. Defaults to . + /// How long the sphere should remain visible. + public static void Sphere(Vector3 origin, float radius, Player player = null, int segments = 16, Color? color = null, float duration = DefaultDuration) + { + Color finalColor = color ?? DefaultColor; + + Vector3[] horizontal = DrawableLines.GetCircle(origin, radius, true, segments); + Send(player, duration, finalColor, horizontal); + + Vector3[] vertical = DrawableLines.GetCircle(origin, radius, false, segments); + Send(player, duration, finalColor, vertical); + } + + /// + /// Draws the edges of a object (box). + /// + /// The object to visualize. + /// The to show the bounds to. If , it is shown to all players. + /// How long the bounds should remain visible. + /// The color of the box. Defaults to . + public static void Bounds(Bounds bounds, Player player = null, float duration = DefaultDuration, Color? color = null) + { + Color finalColor = color ?? DefaultColor; + Vector3 center = bounds.center; + Vector3 extents = bounds.extents; + + Vector3[] array = new Vector3[5]; + Vector3[] array2 = new Vector3[5]; + + array[0] = center + new Vector3(-extents.x, -extents.y, -extents.z); + array[1] = center + new Vector3(extents.x, -extents.y, -extents.z); + array[2] = center + new Vector3(extents.x, -extents.y, extents.z); + array[3] = center + new Vector3(-extents.x, -extents.y, extents.z); + array[4] = array[0]; + + array2[0] = center + new Vector3(-extents.x, extents.y, -extents.z); + array2[1] = center + new Vector3(extents.x, extents.y, -extents.z); + array2[2] = center + new Vector3(extents.x, extents.y, extents.z); + array2[3] = center + new Vector3(-extents.x, extents.y, extents.z); + array2[4] = array2[0]; + + Send(player, duration, finalColor, array); + Send(player, duration, finalColor, array2); + + for (int i = 0; i < 4; i++) + { + Send(player, duration, finalColor, array[i], array2[i]); + } + } + + private static void Send(Player player, float duration, Color color, params Vector3[] points) + { + if (points == null || points.Length < 2) + return; + + if (player != null) + player.Connection.Send(new DrawableLineMessage(duration, color, points)); + else + NetworkServer.SendToReady(new DrawableLineMessage(duration, color, points)); + } + } +} \ No newline at end of file