mirror of
https://github.com/Xevion/Boids.git
synced 2026-01-31 04:23:34 -06:00
add better redraw checks for EditorGUI, add build macro (CustomEditor needed), remove target frame rate
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user