diff --git a/Boids/Assets/Scripts/Boid.cs b/Boids/Assets/Scripts/Boid.cs index 62e2680..934cfba 100644 --- a/Boids/Assets/Scripts/Boid.cs +++ b/Boids/Assets/Scripts/Boid.cs @@ -261,41 +261,4 @@ public class Boid : MonoBehaviour { // Add points to LineRenderer line.SetPositions(points); } - - private void DrawArcCentered(float radius, float centerAngle, float angleWidth, string childName) { - float half = angleWidth / 2f; - DrawArc(radius, Util.AddAngle(centerAngle, -half), Util.AddAngle(centerAngle, half), childName); - } - - private void DrawArc(float radius, float from, float to, string childName) { - // Create a new child GameObject to hold the LineRenderer Component - var child = new GameObject(childName); - child.transform.SetParent(transform); - child.transform.position = transform.position; - var line = child.AddComponent(); - - int vertexCount = _parent.arcVertexCount != -1 ? _parent.arcVertexCount : (int) Mathf.Abs(from - to) * 2; - - // Setup LineRenderer properties - line.useWorldSpace = false; - line.startWidth = _parent.circleWidth; - line.endWidth = _parent.circleWidth; - line.positionCount = vertexCount + 1 + 2; - - // Calculate points for circle - var pointCount = vertexCount + 1; - var points = new Vector3[pointCount + 2]; - - for (int i = 0; i < pointCount; i++) { - // Magic '180 - angle' - var rad = Mathf.Deg2Rad * Mathf.LerpAngle(from, to, i / (float) pointCount); - points[i + 1] = new Vector3(Mathf.Sin(rad), Mathf.Cos(rad), 0) * radius; - } - - points[0] = new Vector3(0, 0, 0); - points[points.Length - 1] = points[0]; - - // Add points to LineRenderer - line.SetPositions(points); - } } \ No newline at end of file diff --git a/Boids/Assets/Scripts/ShapeDraw.cs b/Boids/Assets/Scripts/ShapeDraw.cs index 7c7b7dd..176d37e 100644 --- a/Boids/Assets/Scripts/ShapeDraw.cs +++ b/Boids/Assets/Scripts/ShapeDraw.cs @@ -4,6 +4,12 @@ /// A simple static utility class that assists with drawing shapes using the LineRenderer class. /// public class ShapeDraw { + public static float CircleWidth = 1f; + public static float ArcWidth = 1f; + public static int CircleVertexCount = 360; + public static int ArcVertexCount = 77; + + /// /// Draw a Arc aimed straight up with a certain angle width and radius. /// Use to point the Arc at a certain direction. @@ -11,10 +17,29 @@ public class ShapeDraw { /// The LineRenderer to draw the Arc upon. /// Angle of the Arc /// Radius of the Arc - /// Number of vertexes to be used in the arc, clamp minimum 3 /// - public static void DrawArc(LineRenderer lineRenderer, float angle, float radius, int vertexCount) { + public static void DrawArc(LineRenderer lineRenderer, float angle, float radius) { + // Setup LineRenderer properties + lineRenderer.useWorldSpace = false; + lineRenderer.startWidth = ArcWidth; + lineRenderer.endWidth = ArcWidth; + lineRenderer.positionCount = ArcVertexCount + 1 + 2; + + // Calculate points for circle + var pointCount = ArcVertexCount + 1; + var points = new Vector3[pointCount + 2]; + for (int i = 0; i < pointCount; i++) { + // Magic '180 - angle' + var rad = Mathf.Deg2Rad * Mathf.LerpAngle(0, angle, i / (float) pointCount); + points[i + 1] = new Vector3(Mathf.Sin(rad), Mathf.Cos(rad), 0) * radius; + } + + points[0] = new Vector3(0, 0, 0); + points[points.Length - 1] = points[0]; + + // Add points to LineRenderer + lineRenderer.SetPositions(points); } ///