From 97df401b84d77b2a8ef54aaff825cef1b580d0fd Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 5 May 2020 10:14:35 -0500 Subject: [PATCH] use switch statement for sampling method selection, add tooltips to inspector attributes --- procedural-placement/Assets/CubeRendering.cs | 31 +++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/procedural-placement/Assets/CubeRendering.cs b/procedural-placement/Assets/CubeRendering.cs index 3d1b8c5..a5fe82d 100644 --- a/procedural-placement/Assets/CubeRendering.cs +++ b/procedural-placement/Assets/CubeRendering.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Net; using UnityEditor; using UnityEngine; @@ -9,14 +10,19 @@ public enum SamplingTypes { }; public class CubeRendering : MonoBehaviour { + [Tooltip("The sampling method used to generate points")] public SamplingTypes samplingMethod = SamplingTypes.Random; + [Tooltip("The number of points (spheres) placed inside the region")] 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; // Store the previous value, only useful for the inspector - [Tooltip("Testing.")] private int _prevNumPoints; + private SamplingTypes _samplingMethod; + private int _prevNumPoints; private Vector2 _prevRegionSize; private List _points; @@ -28,10 +34,15 @@ public class CubeRendering : MonoBehaviour { _prevNumPoints = numPoints; _prevRegionSize = regionSize; - if (samplingMethod == SamplingTypes.Random) - _points = PointGeneration.random_sampling(numPoints, regionSize, transform.position); - else if (samplingMethod == SamplingTypes.Poisson) { - _points = new List(); + switch (samplingMethod) { + case SamplingTypes.Random: + _points = PointGeneration.random_sampling(numPoints, regionSize, transform.position); + break; + case SamplingTypes.Poisson: + _points = new List(); + break; + default: + throw new ArgumentOutOfRangeException(); } } } @@ -42,9 +53,9 @@ public class CubeRendering : MonoBehaviour { new Vector3(regionSize.x * 2 + cubeSize, regionSize.y * 2 + cubeSize, cubeSize)); // Render spheres at every point - if (_points != null) - foreach (Vector2 point in _points) { - Gizmos.DrawSphere(point, cubeSize); - } + if (_points == null) return; + foreach (var point in _points) { + Gizmos.DrawSphere(point, cubeSize); + } } } \ No newline at end of file