From 8e976e31962bde51d7de77afbf6bce1567a7b04a Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 28 May 2020 08:36:04 -0500 Subject: [PATCH] private isFocused, remove _renderers, remove unused DirectionFromAngle, make Draw's redraw arg explicit --- Boids/Assets/Scripts/Boid.cs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Boids/Assets/Scripts/Boid.cs b/Boids/Assets/Scripts/Boid.cs index 1ae6104..2d8c273 100644 --- a/Boids/Assets/Scripts/Boid.cs +++ b/Boids/Assets/Scripts/Boid.cs @@ -10,16 +10,14 @@ public class Boid : MonoBehaviour { [NonSerialized] private Vector2 _velocity; [NonSerialized] private bool _isWrappingX = false; [NonSerialized] private bool _isWrappingY = false; - [NonSerialized] private Renderer[] _renderers; [NonSerialized] private Vector2 _centeringVelocity; [NonSerialized] private int _latestNeighborhoodCount = 0; [NonSerialized] private BoidController _parent; - [NonSerialized] public bool isFocused = false; + [NonSerialized] private bool _isFocused = false; private void Start() { _parent = transform.parent .GetComponent(); // Parent used to perform physics math without caching - _renderers = transform.GetComponents(); // Acquire Renderer(s) to check for Boid visibility _velocity = Util.GetRandomVelocity(_parent.boidStartVelocity); // Acquire a Velocity Vector with a magnitude _position = transform.position; // Track 2D position separately transform.name = $"Boid {transform.GetSiblingIndex()}"; // Name the Game Object so Boids can be tracked somewhat @@ -76,14 +74,6 @@ public class Boid : MonoBehaviour { } #endif - public Vector3 DirectionFromAngle(float _angleInDeg, bool _global) { - if (_global == false) { - _angleInDeg += transform.eulerAngles.z; - } - - return new Vector3(Mathf.Sin(_angleInDeg * Mathf.Deg2Rad), Mathf.Cos(_angleInDeg * Mathf.Deg2Rad), 0); - } - private Vector2 SteerTowards(Vector2 vector) { Vector2 v = vector.normalized * _parent.maxSpeed - _velocity; return Vector2.ClampMagnitude(v, _parent.maxSteerForce); @@ -185,9 +175,11 @@ public class Boid : MonoBehaviour { List flock = new List(); foreach (Boid boid in boids) { + // Distance Check if (boid == this || Vector2.Distance(this._position, boid._position) > radius) continue; + // FOV Check if (_parent.enableFOVChecks) { float angle1 = Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y); float angle2 = Mathf.Rad2Deg * -Mathf.Atan2(boid._velocity.x, boid._velocity.y); @@ -203,23 +195,23 @@ public class Boid : MonoBehaviour { // Sets up a Boid to be 'Focused', adds Circles around object and changes color public void EnableFocusing() { - if (isFocused) { + if (_isFocused) { Debug.LogWarning("enableFocusing called on previously focused Boid"); return; } - isFocused = true; + _isFocused = true; // Update Mesh Material Color var triangle = transform.GetComponent(); triangle.meshRenderer.material.color = Color.red; - Draw(); + Draw(false); } // Disable focusing, removing LineRenderers and resetting color public void DisableFocusing() { - isFocused = false; + _isFocused = false; // Update Mesh Material Color var oldTriangle = transform.GetComponent(); @@ -230,7 +222,7 @@ public class Boid : MonoBehaviour { Destroy(child.gameObject); } - public void Draw(bool redraw = false) { + public void Draw(bool redraw) { if (redraw) foreach (Transform child in transform) Destroy(child.gameObject);