パーリンノイズを作成して重ねたいのですが、インスペクターが見にくいため、エディタ拡張で少し見やすくしようと思ったのですが、
boolでノイズをオートアップデートするかどうかのチェックが入っていると、スライダーが動かなくなります。
ただ単にノイズ作成の関数を呼び出さなければスライダーは動くようなのですが、なぜスライダーが動かなくなるのでしょうか?
ノイズ作成
c#
1using System.Collections; 2using System.Collections.Generic; 3using System.Linq; 4using UnityEngine; 5 6public class noise001 : MonoBehaviour { 7 8 public Vector2 size; 9 public int octave; 10 11 public bool autUpdat; 12 13 14 public List<NoiseArray> noise_array; 15 16 17 [System.Serializable] 18 public class NoiseArray 19 { 20 [Range(1,0)] 21 public float frewuency; 22 public Vector2 org; 23 public float scale; 24 } 25 26public void NoiseCreate() 27 { 28 float Objx = transform.position.x; 29 float Objy = transform.position.z; 30 float[,] PerlinNoiseArry = new float[(int)size.x, (int)size.y]; 31 32 for (int i = 0; i < noise_array.Count; i++) 33 { 34 for (int x = 0; x < size.x; x++) 35 { 36 for (int y = 0; y < size.y; y++) 37 { 38 float noiseX = x / size.x * noise_array[i].scale; 39 float noiseY = y / size.y * noise_array[i].scale; 40 float NoisTmp = Mathf.PerlinNoise(noiseX, noiseY); 41 42 PerlinNoiseArry[x, y] = NoisTmp; 43 } 44 } 45 } 46 47 48 49 display(PerlinNoiseArry); 50 } 51 52 public Renderer rend; 53 Color[] color; 54 void display(float[,] Array) 55 { 56 rend = GetComponent<Renderer>(); 57 Material m = new Material(rend.sharedMaterial); 58 color = new Color[(int)size.x * (int)size.y]; 59 60 for (int x = 0; x < size.x; x++) 61 { 62 for (int y = 0; y < size.y; y++) 63 { 64 color[x * (int)size.y + y] = Color.Lerp(Color.black, Color.white, Array[x, y]); 65 } 66 } 67 68 Texture2D texture = new Texture2D((int)size.x, (int)size.y); 69 70 texture.SetPixels(color); 71 texture.Apply(); 72 rend.material = m; 73 rend.sharedMaterial.mainTexture = texture; 74 rend.transform.localScale = new Vector3((int)size.x, 1, (int)size.y); 75 } 76
エディタの拡張
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEditor; 5 6 7[CustomEditor(typeof(noise001))] 8public class noise001Editor : Editor 9{ 10 11 SerializedProperty itemsProp; 12 int currentIndex; 13 14 private void OnEnable() 15 { 16 } 17 18 19 public override void OnInspectorGUI() 20 { 21 serializedObject.Update(); 22 23 noise001 noise = (noise001)target; 24 25 noise.OctChange(); 26 27 if (noise.autUpdat) 28 { 29 noise.NoiseCreate(); 30 } 31 32 noise.size = EditorGUILayout.Vector2Field("Size", noise.size); 33 noise.octave = EditorGUILayout.IntField("octave", noise.octave); 34 noise.autUpdat = EditorGUILayout.Toggle("autoUpdata", noise.autUpdat); 35 36 itemsProp = serializedObject.FindProperty("noise_array"); 37 if (noise != null && itemsProp.arraySize != 0) 38 { 39 currentIndex = EditorGUILayout.IntSlider(currentIndex, 0, itemsProp.arraySize - 1); 40 41 SerializedProperty selectedItemProp = itemsProp.GetArrayElementAtIndex(currentIndex); 42 EditorGUILayout.PropertyField(selectedItemProp,true); 43 selectedItemProp.isExpanded = true; 44 } 45 46 serializedObject.ApplyModifiedProperties(); 47 48 } 49}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。