mirror of
https://github.com/Xevion/Boids.git
synced 2025-12-10 02:06:33 -06:00
use DestroyImmediate to fix pause Boid FOV edits creating duplicate LineRenderers, fix arc calculations and rotate correctly, FOV arc finally 'fixed' properly (again), fix XML docs/comments
This commit is contained in:
@@ -231,7 +231,7 @@ public class Boid : MonoBehaviour {
|
||||
|
||||
// Destroy Line Renderers (and child GameObjects)
|
||||
foreach (Transform child in transform)
|
||||
Destroy(child.gameObject);
|
||||
DestroyImmediate(child.gameObject);
|
||||
Array.Clear(_lineRenderers, 0, _lineRenderers.Length);
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ public class Boid : MonoBehaviour {
|
||||
if (_parent.enableFOVChecks) {
|
||||
// Set FOV Arc rotation to mimic Boid transform rotation
|
||||
_lineRenderers[2].transform.rotation = transform.rotation;
|
||||
_lineRenderers[2].transform.Rotate(0, 0, _parent.boidFOV / 2f + 180);
|
||||
_lineRenderers[2].transform.Rotate(0, 0, _parent.boidFOV / 2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// A simple static utility class that assists with drawing shapes using the <c>LineRenderer</c> class.
|
||||
/// </summary>
|
||||
public class ShapeDraw {
|
||||
public static class ShapeDraw {
|
||||
public static float CircleWidth = 1f;
|
||||
public static float ArcWidth = 1f;
|
||||
public static int CircleVertexCount = 360;
|
||||
@@ -12,12 +12,12 @@ public class ShapeDraw {
|
||||
|
||||
/// <summary>
|
||||
/// Draw a Arc aimed straight up with a certain angle width and radius.
|
||||
/// Use <see cref="RotateLineRenderer"/> to point the Arc at a certain direction.
|
||||
/// This Arc is not direct at any specific angle and start from 0 degrees and ends at <c>angle</c> degrees.
|
||||
/// You should rotate the <c>LineRenderer</c> to direct it at a specific point.
|
||||
/// </summary>
|
||||
/// <param name="lineRenderer">The LineRenderer to draw the Arc upon.</param>
|
||||
/// <param name="angle">Angle of the Arc</param>
|
||||
/// <param name="angle">Angle (width) of the Arc</param>
|
||||
/// <param name="radius">Radius of the Arc</param>
|
||||
/// <seealso cref="RotateLineRenderer"/>
|
||||
public static void DrawArc(LineRenderer lineRenderer, float angle, float radius) {
|
||||
// Setup LineRenderer properties
|
||||
lineRenderer.useWorldSpace = false;
|
||||
@@ -29,9 +29,9 @@ public class ShapeDraw {
|
||||
var pointCount = ArcVertexCount + 1;
|
||||
var points = new Vector3[pointCount + 2];
|
||||
|
||||
// Generate all points
|
||||
for (int i = 0; i < pointCount; i++) {
|
||||
// Magic '180 - angle'
|
||||
var rad = Mathf.Deg2Rad * Mathf.LerpAngle(0, angle, i / (float) pointCount);
|
||||
var rad = Mathf.Deg2Rad * Mathf.Lerp(0, angle, (float) i / pointCount);
|
||||
points[i + 1] = new Vector3(Mathf.Sin(rad), Mathf.Cos(rad), 0) * radius;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ public class ShapeDraw {
|
||||
/// <summary>
|
||||
/// Draw a Circle with a specific radius and number of vertexes (detail level)
|
||||
/// </summary>
|
||||
/// <param name="lineRenderer"></param>
|
||||
/// <param name="lineRenderer">The LineRenderer to draw the Circle upon</param>
|
||||
/// <param name="radius">Radius of the Circle</param>
|
||||
public static void DrawCircle(LineRenderer lineRenderer, float radius) {
|
||||
// Setup LineRenderer properties
|
||||
lineRenderer.useWorldSpace = false;
|
||||
@@ -64,12 +65,4 @@ public class ShapeDraw {
|
||||
// Add points to LineRenderer
|
||||
lineRenderer.SetPositions(points);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="lineRenderer"></param>
|
||||
public static void RotateLineRenderer(LineRenderer lineRenderer) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user