Guest User

Untitled

a guest
Dec 30th, 2020
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. [CustomEditor(typeof(Planet))]
  5. public class PlanetEditor : Editor
  6. {
  7.     Planet planet;
  8.  
  9.     public override void OnInspectorGUI()
  10.     {
  11.         if (DrawDefaultInspector())
  12.         {
  13.             if (planet.autoUpdate)
  14.             {
  15.                 planet.BuildPlanet();
  16.             }
  17.         }
  18.  
  19.         if (GUILayout.Button("Build"))
  20.         {
  21.             planet.BuildPlanet();
  22.         }
  23.  
  24.         DrawSettingsEditor(planet.shapeSettings, planet.OnShapeSettingsUpdate);
  25.         DrawSettingsEditor(planet.colorSettings, planet.OnColorSettingsUpdate);
  26.     }
  27.  
  28.     public void DrawSettingsEditor(Object settings, System.Action onSettingsUpdate)
  29.     {
  30.         Editor editor = CreateEditor(settings);
  31.         editor.OnInspectorGUI();
  32.  
  33.         using (var check = new EditorGUI.ChangeCheckScope())
  34.         {
  35.             if (check.changed)
  36.             {
  37.                 onSettingsUpdate();
  38.             }
  39.         }
  40.     }
  41.  
  42.     public void OnEnable()
  43.     {
  44.         planet = (Planet) target;
  45.     }
  46. }
RAW Paste Data