add simple editor for GridController

This commit is contained in:
Xevion
2020-07-08 03:07:10 -05:00
parent 5fc767cede
commit 6324986648
4 changed files with 30 additions and 13 deletions

8
Climb/Assets/Editor.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 70aea28051ad4379b1846c3e27a930bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(GridController))]
public class GridControllerEditor : UnityEditor.Editor {
public override void OnInspectorGUI() {
var controller = (GridController) target;
controller.size = EditorGUILayout.IntSlider("Size", controller.size, 1, 2048);
controller.perlinScale = EditorGUILayout.Slider("Perlin Scale", controller.perlinScale, 0.001f, 0.5f);
controller.offsetChange.x = EditorGUILayout.IntSlider("Horizontal Speed", (int) controller.offsetChange.x, 0, 250);
controller.offsetChange.y = EditorGUILayout.IntSlider("Horizontal Speed", (int) controller.offsetChange.y, 0, 250);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 68c776dfa8a845ff84eb1cc937a6dbb1
timeCreated: 1594194214

View File

@@ -8,7 +8,7 @@ public class GridController : MonoBehaviour {
public float perlinScale = 16; public float perlinScale = 16;
public Vector2 offsetChange = new Vector2(1, 0); public Vector2 offsetChange = new Vector2(1, 0);
private Vector2 offset; private Vector2 offset;
public Material gridMaterial; public Material gridMaterial;
private float[] _values; private float[] _values;
private ComputeBuffer buffer; private ComputeBuffer buffer;
@@ -21,9 +21,6 @@ public class GridController : MonoBehaviour {
SetValue(x, y, Mathf.PerlinNoise((x + offset.x) * perlinScale, (y + offset.y) * perlinScale)); SetValue(x, y, Mathf.PerlinNoise((x + offset.x) * perlinScale, (y + offset.y) * perlinScale));
} }
} }
// Debug.Log($"{_values.Length} values regenerated.");
// Debug.Log(String.Join(", ", _values.ToList().ConvertAll(i => i.ToString()).ToArray()));
} }
private void Start() { private void Start() {
@@ -41,15 +38,9 @@ public class GridController : MonoBehaviour {
} }
private void Update() { private void Update() {
// if (Input.GetKey("space")) { regenerateValues();
// Debug.Log("Reloading values..."); UpdateShader();
regenerateValues(); offset += offsetChange * Time.deltaTime;
// Debug.Log("Values generated. Updating Shader...");
UpdateShader();
// Debug.Log("Done.");
offset += offsetChange * Time.deltaTime;
// }
} }
private void OnApplicationQuit() { private void OnApplicationQuit() {