void DrawSelectedNodeDetails(NodeBase node) { if (previewNeedsUpdate || lastSelected != node) { preview = new Texture2D(230, 230); if (node.Module != null && previewCalculation == null) { previewCalculation = new NoiseCalculation(node.Module, 230, 230); } previewNeedsUpdate = false; lastSelected = node; } if (previewCalculation != null && previewCalculation.Done) { preview = previewCalculation.Noise.GetTexture(); previewCalculation = null; } var state = mainEditorState as NoiseDesignerState; EditorGUILayout.Space(); EditorGUILayout.LabelField("Selected Node:"); GUILayout.Box(preview); EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Apply to terrain:"); terrain = EditorGUILayout.ObjectField("TerrainData", terrain, typeof(TerrainData), false) as TerrainData; if (GUILayout.Button("Apply")) { Noise2D noise = new Noise2D(terrain.heightmapWidth, terrain.heightmapHeight, node.Module); noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f); terrain.SetHeights(0, 0, noise.GetNormalizedData()); } EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Export as texture:"); state.textureSize = EditorGUILayout.Vector2Field("Texture Size", state.textureSize); if (GUILayout.Button("Save as PNG")) { var path = EditorUtility.SaveFilePanelInProject("Save as PNG", "noise", "png", ""); if (!string.IsNullOrEmpty(path)) { Noise2D noise = new Noise2D((int)state.textureSize.x, (int)state.textureSize.y, node.Module); noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f); var texture = noise.GetTexture(); File.WriteAllBytes(path, texture.EncodeToPNG()); AssetDatabase.Refresh(); } } }
void DrawSelectedNodeDetails(NodeBase node) { if (previewNeedsUpdate || lastSelected != node) { preview = new Texture2D(230, 230); if (node.Module != null && previewCalculation == null) previewCalculation = new NoiseCalculation(node.Module, 230, 230); previewNeedsUpdate = false; lastSelected = node; } if (previewCalculation != null && previewCalculation.Done) { preview = previewCalculation.Noise.GetTexture(); previewCalculation = null; } var state = mainEditorState as NoiseDesignerState; EditorGUILayout.Space(); EditorGUILayout.LabelField("Selected Node:"); GUILayout.Box(preview); EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Apply to terrain:"); terrain = EditorGUILayout.ObjectField("TerrainData", terrain, typeof(TerrainData), false) as TerrainData; if (GUILayout.Button("Apply")) { Noise2D noise = new Noise2D(terrain.heightmapWidth, terrain.heightmapHeight, node.Module); noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f); terrain.SetHeights(0, 0, noise.GetNormalizedData()); } EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Export as texture:"); state.textureSize = EditorGUILayout.Vector2Field("Texture Size", state.textureSize); if (GUILayout.Button("Save as PNG")) { var path = EditorUtility.SaveFilePanelInProject("Save as PNG", "noise", "png", ""); if (!string.IsNullOrEmpty(path)) { Noise2D noise = new Noise2D((int)state.textureSize.x, (int)state.textureSize.y, node.Module); noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f); var texture = noise.GetTexture(); File.WriteAllBytes(path, texture.EncodeToPNG()); AssetDatabase.Refresh(); } } }