From 55dec29413f91a54ba497787f77c353033205179 Mon Sep 17 00:00:00 2001 From: Xevion Date: Wed, 27 May 2020 22:59:24 -0500 Subject: [PATCH] add better redraw checks for EditorGUI, add build macro (CustomEditor needed), remove target frame rate --- Boids/Assets/Scripts/Boid.cs | 9 ++++----- Boids/Assets/Scripts/BoidControllerEditor.cs | 17 +++++++++++------ Boids/Assets/Scripts/UIController.cs | 2 +- Boids/ProjectSettings/GraphicsSettings.asset | 1 - 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Boids/Assets/Scripts/Boid.cs b/Boids/Assets/Scripts/Boid.cs index 452c589..1ae6104 100644 --- a/Boids/Assets/Scripts/Boid.cs +++ b/Boids/Assets/Scripts/Boid.cs @@ -29,10 +29,7 @@ public class Boid : MonoBehaviour { // Updates the rotation of the object based on the Velocity transform.eulerAngles = new Vector3(0, 0, Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y)); - if(isFocused) - Draw(true); - - // Skip Flock Calculations if wrapping in progress + // Skip Flock Calculations if wrapping in progress if (_isWrappingX || _isWrappingY) { UpdateCenteringVelocity(); _position += _centeringVelocity * Time.deltaTime; @@ -72,10 +69,12 @@ public class Boid : MonoBehaviour { Wrapping(); } +#if UNITY_EDITOR private void OnDrawGizmos() { // Show # of Boids in Neighborhood Handles.Label(transform.position, $"{_latestNeighborhoodCount}"); } +#endif public Vector3 DirectionFromAngle(float _angleInDeg, bool _global) { if (_global == false) { @@ -293,8 +292,8 @@ public class Boid : MonoBehaviour { var pointCount = vertexCount + 1; var points = new Vector3[pointCount + 2]; for (int i = 0; i < pointCount; i++) { + // Magic '180 - angle' var rad = Mathf.Deg2Rad * (180 - Mathf.LerpAngle(from, to, i / (float) pointCount)); - // var rad = Mathf.Deg2Rad * (i * 360f / _parent.circleVertexCount); points[i + 1] = new Vector3(Mathf.Sin(rad) * radius, Mathf.Cos(rad) * radius, 0); } diff --git a/Boids/Assets/Scripts/BoidControllerEditor.cs b/Boids/Assets/Scripts/BoidControllerEditor.cs index b3121be..e248ec5 100644 --- a/Boids/Assets/Scripts/BoidControllerEditor.cs +++ b/Boids/Assets/Scripts/BoidControllerEditor.cs @@ -6,7 +6,8 @@ using UnityEngine; public class BoidControllerEditor : Editor { public override void OnInspectorGUI() { var controller = (BoidController) target; - + bool redraw = false; + // Boid Count update EditorGUI.BeginChangeCheck(); controller.boidCount = EditorGUILayout.IntSlider("Boid Count", controller.boidCount, 1, 500); @@ -31,18 +32,16 @@ public class BoidControllerEditor : Editor { controller.boidGroupRange = EditorGUILayout.Slider("Group Range", controller.boidGroupRange, 0.01f, 7.5f); controller.boidSeparationRange = EditorGUILayout.Slider("Separation Range", controller.boidSeparationRange, 0.01f, 5.0f); controller.boidFOV = EditorGUILayout.Slider("Boid FOV", controller.boidFOV, 1f, 360f); - if (EditorGUI.EndChangeCheck()) - controller.focusedBoid.Draw(true); + redraw = redraw || EditorGUI.EndChangeCheck(); - // Boid Bias Attributes + // Boid Bias Attributes controller.alignmentBias = EditorGUILayout.Slider("Alignment Bias", controller.alignmentBias, 0.001f, 1.5f); controller.cohesionBias = EditorGUILayout.Slider("Cohesion Bias", controller.cohesionBias, 0.001f, 1.5f); controller.separationBias = EditorGUILayout.Slider("Separation Bias", controller.separationBias, 0.001f, 2.5f); controller.boundaryBias = EditorGUILayout.Slider("Boundary Bias", controller.boundaryBias, 0.01f, 1.5f); controller.localFlocks = EditorGUILayout.Toggle("Use Groups?", controller.localFlocks); - controller.edgeWrapping = EditorGUILayout.Toggle("Enforce Wrapping?", controller.edgeWrapping); - + controller.edgeWrapping = EditorGUILayout.Toggle("Enable Wrapping?", controller.edgeWrapping); controller.enableAlignment = EditorGUILayout.Toggle("Enable Alignment?", controller.enableAlignment); controller.enableCohesion = EditorGUILayout.Toggle("Enable Cohesion?", controller.enableCohesion); controller.enableSeparation = EditorGUILayout.Toggle("Enable Separation?", controller.enableSeparation); @@ -50,8 +49,14 @@ public class BoidControllerEditor : Editor { controller.enableFOVChecks = EditorGUILayout.Toggle("Enable FOV?", controller.enableFOVChecks); // Boid Rendering + EditorGUI.BeginChangeCheck(); controller.circleVertexCount = EditorGUILayout.IntSlider("Circle Vertex Count", controller.circleVertexCount, 4, 360); controller.circleWidth = EditorGUILayout.Slider("Circle Line Width", controller.circleWidth, 0.01f, 1f); + redraw = redraw || EditorGUI.EndChangeCheck(); + + // Inspector elements related to Boid Focusing have changed - redraw! + if (redraw) + controller.focusedBoid.Draw(true); } } #endif \ No newline at end of file diff --git a/Boids/Assets/Scripts/UIController.cs b/Boids/Assets/Scripts/UIController.cs index 06f6ce4..d0bd109 100644 --- a/Boids/Assets/Scripts/UIController.cs +++ b/Boids/Assets/Scripts/UIController.cs @@ -76,7 +76,7 @@ public class UIController : MonoBehaviour { private void Start() { // Set Target Application Framerate - Application.targetFrameRate = 90; + // Application.targetFrameRate = 90; // Basic variable setup _currentUI = UIStance.Title; diff --git a/Boids/ProjectSettings/GraphicsSettings.asset b/Boids/ProjectSettings/GraphicsSettings.asset index 3486ea4..ab4d074 100644 --- a/Boids/ProjectSettings/GraphicsSettings.asset +++ b/Boids/ProjectSettings/GraphicsSettings.asset @@ -34,7 +34,6 @@ GraphicsSettings: - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: 16002, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}