From 0fdc28810a74aae8ef60dae83c09a195fd8c4ab6 Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 5 May 2020 14:20:50 -0500 Subject: [PATCH] make methods private, switch to var type, fix sphere offsets and draw correctly, add sampling method update to OnValidate event --- procedural-placement/Assets/CubeRendering.cs | 17 +++++++++-------- procedural-placement/Assets/PointGeneration.cs | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/procedural-placement/Assets/CubeRendering.cs b/procedural-placement/Assets/CubeRendering.cs index a5fe82d..44cfcf2 100644 --- a/procedural-placement/Assets/CubeRendering.cs +++ b/procedural-placement/Assets/CubeRendering.cs @@ -16,7 +16,6 @@ public class CubeRendering : MonoBehaviour { public int numPoints = 100; [Tooltip("The size of the rendered cubes")] public float cubeSize = 1; - [Tooltip("The Size of the region points are generated in")] public Vector2 regionSize = Vector2.one; @@ -26,13 +25,15 @@ public class CubeRendering : MonoBehaviour { private Vector2 _prevRegionSize; private List _points; - - void OnValidate() { + + private void OnValidate() { // Check to see if point position related values changed. CubeSize is rendering only, so we ignore it. - if (numPoints != _prevNumPoints || _prevRegionSize != regionSize) { + if (numPoints != _prevNumPoints || _prevRegionSize != regionSize + || samplingMethod != _samplingMethod) { // Update the tracking values _prevNumPoints = numPoints; _prevRegionSize = regionSize; + _samplingMethod = samplingMethod; switch (samplingMethod) { case SamplingTypes.Random: @@ -47,15 +48,15 @@ public class CubeRendering : MonoBehaviour { } } - void OnDrawGizmos() { + private void OnDrawGizmos() { // Draw a wireframe around the entire region Gizmos.DrawWireCube(this.transform.position, new Vector3(regionSize.x * 2 + cubeSize, regionSize.y * 2 + cubeSize, cubeSize)); // Render spheres at every point if (_points == null) return; - foreach (var point in _points) { - Gizmos.DrawSphere(point, cubeSize); - } + var pos = transform.position; + foreach (var point in _points) + Gizmos.DrawSphere(new Vector3(point.x + pos.x, point.y + pos.y, pos.z), cubeSize); } } \ No newline at end of file diff --git a/procedural-placement/Assets/PointGeneration.cs b/procedural-placement/Assets/PointGeneration.cs index 67394d5..8f2c93d 100644 --- a/procedural-placement/Assets/PointGeneration.cs +++ b/procedural-placement/Assets/PointGeneration.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; using UnityEngine; -public class PointGeneration { +public static class PointGeneration { public static List random_sampling(int numPoints, Vector2 range, Vector2 offset) { // Create a new empty list of points, and add some randomly - List points = new List(); - for (int i = 0; i < numPoints; i++) { + var points = new List(); + for (var i = 0; i < numPoints; i++) { points.Add( new Vector2( Random.Range(-range.x, range.x),