Repository navigation
Expand file tree
/
Copy pathNoiseVisualizer.cs
More file actions
67 lines (56 loc) · 1.64 KB
/
Copy pathNoiseVisualizer.cs
File metadata and controls
67 lines (56 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class NoiseVisualizer : MonoBehaviour
{
public NoiseSettings settings;
public int resolution = 256;
public Renderer _renderer;
public void Start()
{
_renderer = GetComponent<Renderer>();
}
private void OnValidate()
{
// UpdateTexture();
}
public void UpdateTexture()
{
Color[] pixs = new Color[resolution * resolution];
for (var x = 0; x < resolution; x++)
{
for (var y = 0; y < resolution; y++)
{
var value = MyNoise.OctavePerlin(x, y, settings);
if (value > 0.9f)
{
var g = 0;
}
var color = new Color(value, value, value);
pixs[y * resolution + x] = color;
}
}
var texture = new Texture2D(resolution, resolution);
texture.SetPixels(pixs);
texture.Apply();
_renderer.sharedMaterial.mainTexture = texture;
}
#if UNITY_EDITOR
[CustomEditor(typeof(NoiseVisualizer))]
public class NoiseVisualizerEditor : Editor
{
public override void OnInspectorGUI()
{
var biomeGenerator = (NoiseVisualizer)this.target;
DrawDefaultInspector();
if (GUILayout.Button("Update Texture"))
{
biomeGenerator.UpdateTexture();
}
var customEditor = Editor.CreateEditor(biomeGenerator.settings);
customEditor.OnInspectorGUI();
}
}
#endif
}