mirror of
https://github.com/Xevion/Boids.git
synced 2026-01-31 08:23:35 -06:00
reset circle/arc/ width/vertexcount with shapedraw, timescale edit, new static array LineRenderers, finished arc drawing base
This commit is contained in:
@@ -15,6 +15,8 @@ public class Boid : MonoBehaviour {
|
|||||||
[NonSerialized] public List<Boid> latestNeighborhood;
|
[NonSerialized] public List<Boid> latestNeighborhood;
|
||||||
[NonSerialized] private BoidController _parent;
|
[NonSerialized] private BoidController _parent;
|
||||||
[NonSerialized] public bool _isFocused = false;
|
[NonSerialized] public bool _isFocused = false;
|
||||||
|
[NonSerialized] private LineRenderer[] _lineRenderers;
|
||||||
|
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
_parent = transform.parent
|
_parent = transform.parent
|
||||||
@@ -188,6 +190,7 @@ public class Boid : MonoBehaviour {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Boid passed all checks, add to local Flock list
|
||||||
flock.Add(boid);
|
flock.Add(boid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +206,12 @@ public class Boid : MonoBehaviour {
|
|||||||
|
|
||||||
_isFocused = true;
|
_isFocused = true;
|
||||||
|
|
||||||
|
// Create all LineRenderers
|
||||||
|
_lineRenderers = new LineRenderer[3];
|
||||||
|
_lineRenderers[0] = GetLineRenderer("Group Range");
|
||||||
|
_lineRenderers[1] = GetLineRenderer("Separation Range");
|
||||||
|
_lineRenderers[2] = GetLineRenderer("FOV Arc");
|
||||||
|
|
||||||
// Update Mesh Material Color
|
// Update Mesh Material Color
|
||||||
var triangle = transform.GetComponent<Triangle>();
|
var triangle = transform.GetComponent<Triangle>();
|
||||||
triangle.meshRenderer.material.color = Color.red;
|
triangle.meshRenderer.material.color = Color.red;
|
||||||
@@ -219,9 +228,11 @@ public class Boid : MonoBehaviour {
|
|||||||
var oldTriangle = transform.GetComponent<Triangle>();
|
var oldTriangle = transform.GetComponent<Triangle>();
|
||||||
oldTriangle.meshRenderer.material.color = new Color32(49, 61, 178, 255);
|
oldTriangle.meshRenderer.material.color = new Color32(49, 61, 178, 255);
|
||||||
|
|
||||||
|
|
||||||
// Destroy Line Renderers (and child GameObjects)
|
// Destroy Line Renderers (and child GameObjects)
|
||||||
foreach (Transform child in transform)
|
foreach (Transform child in transform)
|
||||||
Destroy(child.gameObject);
|
Destroy(child.gameObject);
|
||||||
|
Array.Clear(_lineRenderers, 0, _lineRenderers.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -231,22 +242,30 @@ public class Boid : MonoBehaviour {
|
|||||||
/// <returns>A LineRenderer</returns>
|
/// <returns>A LineRenderer</returns>
|
||||||
public LineRenderer GetLineRenderer(string childName) {
|
public LineRenderer GetLineRenderer(string childName) {
|
||||||
var child = new GameObject(childName);
|
var child = new GameObject(childName);
|
||||||
|
// Make object a child of Boid, set position as such
|
||||||
child.transform.SetParent(transform);
|
child.transform.SetParent(transform);
|
||||||
child.transform.position = transform.position;
|
child.transform.position = transform.position;
|
||||||
|
// add and return LineRenderer component
|
||||||
return child.AddComponent<LineRenderer>();
|
return child.AddComponent<LineRenderer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(bool redraw) {
|
public void Draw(bool redraw) {
|
||||||
if (redraw)
|
// Clear positions when redrawing
|
||||||
foreach (Transform child in transform)
|
if(redraw)
|
||||||
Destroy(child.gameObject);
|
foreach (LineRenderer lineRenderer in _lineRenderers)
|
||||||
|
lineRenderer.positionCount = 0;
|
||||||
|
|
||||||
// Add a LineRenderer for Radius Drawing
|
// Add a LineRenderer for Radius Drawing
|
||||||
DrawCircle(_parent.boidSeparationRange, "Separation Range Circle");
|
if(_parent.enableFOVChecks)
|
||||||
DrawCircle(_parent.boidGroupRange, "Group Range Circle");
|
ShapeDraw.DrawArc(_lineRenderers[2], _parent.boidFOV, _parent.boidGroupRange); // FOV Arc
|
||||||
|
else
|
||||||
|
ShapeDraw.DrawCircle(_lineRenderers[0], _parent.boidGroupRange); // Group Circle
|
||||||
|
ShapeDraw.DrawCircle(_lineRenderers[1], _parent.boidSeparationRange); // Separation Circle
|
||||||
|
|
||||||
// Draw FOV Line
|
if (_parent.enableFOVChecks) {
|
||||||
DrawArcCentered(_parent.boidGroupRange, Util.Vector2ToAngle(_velocity),
|
// Set FOV Arc rotation to mimic Boid transform rotation
|
||||||
_parent.boidFOV, "FOV Arc");
|
_lineRenderers[2].transform.rotation = transform.rotation;
|
||||||
|
_lineRenderers[2].transform.Rotate(0, 0, _parent.boidFOV / 2f + 180);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,6 +97,13 @@ public class BoidController : MonoBehaviour {
|
|||||||
Boundary = new Rect(Vector2.zero, Space.size * 0.95f);
|
Boundary = new Rect(Vector2.zero, Space.size * 0.95f);
|
||||||
Boundary.center = Space.center;
|
Boundary.center = Space.center;
|
||||||
|
|
||||||
|
ShapeDraw.CircleWidth = circleWidth;
|
||||||
|
ShapeDraw.ArcWidth = circleWidth;
|
||||||
|
ShapeDraw.CircleVertexCount = circleVertexCount;
|
||||||
|
// ShapeDraw.ArcVertexCount = arcVertexCount;
|
||||||
|
|
||||||
|
Time.timeScale = 0.3f;
|
||||||
|
|
||||||
AddBoids(boidCount);
|
AddBoids(boidCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user