mirror of
https://github.com/Xevion/procedural-placement.git
synced 2025-12-06 07:15:56 -06:00
use switch statement for sampling method selection, add tooltips to inspector attributes
This commit is contained in:
@@ -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<Vector2> _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<Vector2>();
|
||||
switch (samplingMethod) {
|
||||
case SamplingTypes.Random:
|
||||
_points = PointGeneration.random_sampling(numPoints, regionSize, transform.position);
|
||||
break;
|
||||
case SamplingTypes.Poisson:
|
||||
_points = new List<Vector2>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user