mirror of
https://github.com/Xevion/procedural-placement.git
synced 2025-12-06 01:15:56 -06:00
make methods private, switch to var type, fix sphere offsets and draw correctly, add sampling method update to OnValidate event
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -27,12 +26,14 @@ public class CubeRendering : MonoBehaviour {
|
||||
|
||||
private List<Vector2> _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);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PointGeneration {
|
||||
public static class PointGeneration {
|
||||
public static List<Vector2> random_sampling(int numPoints, Vector2 range, Vector2 offset) {
|
||||
// Create a new empty list of points, and add some randomly
|
||||
List<Vector2> points = new List<Vector2>();
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
var points = new List<Vector2>();
|
||||
for (var i = 0; i < numPoints; i++) {
|
||||
points.Add(
|
||||
new Vector2(
|
||||
Random.Range(-range.x, range.x),
|
||||
|
||||
Reference in New Issue
Block a user