Skip to content

Commit

Permalink
#3 Finished settings editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Oct 31, 2021
1 parent 38d2eea commit 2b0ce4f
Show file tree
Hide file tree
Showing 25 changed files with 2,270 additions and 85 deletions.
Binary file added Assets/PCG/.DS_Store
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions Assets/PCG/Planet Procedural Generation/Editor/PlanetEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(Planet))]
public class PlanetEditor : Editor {

Planet planet;
Editor shapeEditor;
Editor colourEditor;

public override void OnInspectorGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
base.OnInspectorGUI();
if (check.changed)
{
planet.GeneratePlanet();
}
}

if (GUILayout.Button("Generate Planet"))
{
planet.GeneratePlanet();
}

DrawSettingsEditor(planet.shapeSettings, planet.OnShapeSettingsUpdated, ref planet.shapeSettingsFoldout, ref shapeEditor);
DrawSettingsEditor(planet.colourSettings, planet.OnColourSettingsUpdated, ref planet.colourSettingsFoldout, ref colourEditor);
}

void DrawSettingsEditor(Object settings, System.Action onSettingsUpdated, ref bool foldout, ref Editor editor)
{
if (settings != null)
{
foldout = EditorGUILayout.InspectorTitlebar(foldout, settings);
using (var check = new EditorGUI.ChangeCheckScope())
{
if (foldout)
{
CreateCachedEditor(settings, null, ref editor);
editor.OnInspectorGUI();

if (check.changed)
{
if (onSettingsUpdated != null)
{
onSettingsUpdated();
}
}
}
}
}
}

private void OnEnable()
{
planet = (Planet)target;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/PCG/Planet Procedural Generation/Scenes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2b0ce4f

Please sign in to comment.