add better redraw checks for EditorGUI, add build macro (CustomEditor needed), remove target frame rate

This commit is contained in:
Xevion
2020-05-27 22:59:24 -05:00
parent 303e846e0f
commit 55dec29413
4 changed files with 16 additions and 13 deletions
+4 -5
View File
@@ -29,10 +29,7 @@ public class Boid : MonoBehaviour {
// Updates the rotation of the object based on the Velocity // Updates the rotation of the object based on the Velocity
transform.eulerAngles = new Vector3(0, 0, Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y)); transform.eulerAngles = new Vector3(0, 0, Mathf.Rad2Deg * -Mathf.Atan2(_velocity.x, _velocity.y));
if(isFocused) // Skip Flock Calculations if wrapping in progress
Draw(true);
// Skip Flock Calculations if wrapping in progress
if (_isWrappingX || _isWrappingY) { if (_isWrappingX || _isWrappingY) {
UpdateCenteringVelocity(); UpdateCenteringVelocity();
_position += _centeringVelocity * Time.deltaTime; _position += _centeringVelocity * Time.deltaTime;
@@ -72,10 +69,12 @@ public class Boid : MonoBehaviour {
Wrapping(); Wrapping();
} }
#if UNITY_EDITOR
private void OnDrawGizmos() { private void OnDrawGizmos() {
// Show # of Boids in Neighborhood // Show # of Boids in Neighborhood
Handles.Label(transform.position, $"{_latestNeighborhoodCount}"); Handles.Label(transform.position, $"{_latestNeighborhoodCount}");
} }
#endif
public Vector3 DirectionFromAngle(float _angleInDeg, bool _global) { public Vector3 DirectionFromAngle(float _angleInDeg, bool _global) {
if (_global == false) { if (_global == false) {
@@ -293,8 +292,8 @@ public class Boid : MonoBehaviour {
var pointCount = vertexCount + 1; var pointCount = vertexCount + 1;
var points = new Vector3[pointCount + 2]; var points = new Vector3[pointCount + 2];
for (int i = 0; i < pointCount; i++) { 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 * (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); points[i + 1] = new Vector3(Mathf.Sin(rad) * radius, Mathf.Cos(rad) * radius, 0);
} }
+11 -6
View File
@@ -6,7 +6,8 @@ using UnityEngine;
public class BoidControllerEditor : Editor { public class BoidControllerEditor : Editor {
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
var controller = (BoidController) target; var controller = (BoidController) target;
bool redraw = false;
// Boid Count update // Boid Count update
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
controller.boidCount = EditorGUILayout.IntSlider("Boid Count", controller.boidCount, 1, 500); 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.boidGroupRange = EditorGUILayout.Slider("Group Range", controller.boidGroupRange, 0.01f, 7.5f);
controller.boidSeparationRange = EditorGUILayout.Slider("Separation Range", controller.boidSeparationRange, 0.01f, 5.0f); controller.boidSeparationRange = EditorGUILayout.Slider("Separation Range", controller.boidSeparationRange, 0.01f, 5.0f);
controller.boidFOV = EditorGUILayout.Slider("Boid FOV", controller.boidFOV, 1f, 360f); controller.boidFOV = EditorGUILayout.Slider("Boid FOV", controller.boidFOV, 1f, 360f);
if (EditorGUI.EndChangeCheck()) redraw = redraw || EditorGUI.EndChangeCheck();
controller.focusedBoid.Draw(true);
// Boid Bias Attributes // Boid Bias Attributes
controller.alignmentBias = EditorGUILayout.Slider("Alignment Bias", controller.alignmentBias, 0.001f, 1.5f); 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.cohesionBias = EditorGUILayout.Slider("Cohesion Bias", controller.cohesionBias, 0.001f, 1.5f);
controller.separationBias = EditorGUILayout.Slider("Separation Bias", controller.separationBias, 0.001f, 2.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.boundaryBias = EditorGUILayout.Slider("Boundary Bias", controller.boundaryBias, 0.01f, 1.5f);
controller.localFlocks = EditorGUILayout.Toggle("Use Groups?", controller.localFlocks); 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.enableAlignment = EditorGUILayout.Toggle("Enable Alignment?", controller.enableAlignment);
controller.enableCohesion = EditorGUILayout.Toggle("Enable Cohesion?", controller.enableCohesion); controller.enableCohesion = EditorGUILayout.Toggle("Enable Cohesion?", controller.enableCohesion);
controller.enableSeparation = EditorGUILayout.Toggle("Enable Separation?", controller.enableSeparation); controller.enableSeparation = EditorGUILayout.Toggle("Enable Separation?", controller.enableSeparation);
@@ -50,8 +49,14 @@ public class BoidControllerEditor : Editor {
controller.enableFOVChecks = EditorGUILayout.Toggle("Enable FOV?", controller.enableFOVChecks); controller.enableFOVChecks = EditorGUILayout.Toggle("Enable FOV?", controller.enableFOVChecks);
// Boid Rendering // Boid Rendering
EditorGUI.BeginChangeCheck();
controller.circleVertexCount = EditorGUILayout.IntSlider("Circle Vertex Count", controller.circleVertexCount, 4, 360); controller.circleVertexCount = EditorGUILayout.IntSlider("Circle Vertex Count", controller.circleVertexCount, 4, 360);
controller.circleWidth = EditorGUILayout.Slider("Circle Line Width", controller.circleWidth, 0.01f, 1f); 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 #endif
+1 -1
View File
@@ -76,7 +76,7 @@ public class UIController : MonoBehaviour {
private void Start() { private void Start() {
// Set Target Application Framerate // Set Target Application Framerate
Application.targetFrameRate = 90; // Application.targetFrameRate = 90;
// Basic variable setup // Basic variable setup
_currentUI = UIStance.Title; _currentUI = UIStance.Title;
@@ -34,7 +34,6 @@ GraphicsSettings:
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16002, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: [] m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0} type: 0}