Skip to content

Instantly share code, notes, and snippets.

@stipebosnjak
Created November 2, 2018 02:01
Show Gist options
  • Save stipebosnjak/df5f10ec6904d0d3b59d8988ff4e05c0 to your computer and use it in GitHub Desktop.
Save stipebosnjak/df5f10ec6904d0d3b59d8988ff4e05c0 to your computer and use it in GitHub Desktop.
PlanetOrbitEditor - Stash
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PlanetOrbit))]
public class PlanetOrbitEditor : Editor
{
enum setupPlanet { Setup_Orbit, Setup_Rotation, Setup_Seasons }
public override void OnInspectorGUI()
{
var poTarget = (PlanetOrbit)target;
poTarget.Name = EditorGUILayout.TextField("Name: ", poTarget.Name);
poTarget.OrbitalPeriodFactor = EditorGUILayout.FloatField("Orbital period factor: ", poTarget.OrbitalPeriodFactor);
poTarget.DistanceFactor = EditorGUILayout.FloatField("Distance factor: ", poTarget.DistanceFactor);
poTarget.ScaleFactor = EditorGUILayout.FloatField("Scale factor: ", poTarget.ScaleFactor);
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUIUtility.labelWidth = 130;
EditorGUIUtility.fieldWidth = 50;
poTarget.Parent = (Transform)EditorGUILayout.ObjectField("Parent Mass: ", poTarget.Parent, typeof(Transform), true);
EditorGUILayout.Space();
poTarget.LockOrbit = EditorGUILayout.Toggle("Lock Orbit:", poTarget.LockOrbit);
poTarget.TidalLock = EditorGUILayout.Toggle("Tidal Lock:", poTarget.TidalLock);
EditorGUILayout.Space();
EditorGUILayout.Space();
GUILayout.Label("Orbit Display ------------------------------", EditorStyles.boldLabel);
poTarget._DrawOrbit = EditorGUILayout.Toggle("Draw Orbit:", poTarget._DrawOrbit);
if (poTarget._DrawOrbit == true)
{
poTarget.Segments = EditorGUILayout.IntField("Display Segments: ", poTarget.Segments);
poTarget.DisplaySize = EditorGUILayout.FloatField("Display Size: ", poTarget.DisplaySize);
poTarget.DisplayColor = EditorGUILayout.ColorField("Display Color: ", poTarget.DisplayColor);
EditorGUILayout.Space();
poTarget.UseTexture = EditorGUILayout.Toggle("Use Texture:", poTarget.UseTexture);
}
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
//SetupPlanet = EditorGUILayout.EnumPopup("Planet Options:",SetupPlanet);
GUILayout.Label("Planet Orbit ------------------------------", EditorStyles.boldLabel);
EditorGUILayout.Space();
//if(SetupPlanet == 0){
poTarget.AxialTilt = EditorGUILayout.Slider("Axial Tilt: ", poTarget.AxialTilt, 0, 360);
poTarget.OrbitalDistance = EditorGUILayout.FloatField("Orbital Distance: ", poTarget.OrbitalDistance);
poTarget.OrbitAngle = EditorGUILayout.FloatField("Orbit Angle: ", poTarget.OrbitAngle);
EditorGUILayout.Space();
poTarget.OrbitOffset = EditorGUILayout.Vector3Field("Orbit Center Offset: ", poTarget.OrbitOffset);
EditorGUILayout.Space();
EditorGUILayout.Space();
poTarget.OrbitPosOffset = EditorGUILayout.Slider("Start Orbital Offset: ", poTarget.OrbitPosOffset, 0, 360);
EditorGUILayout.Space();
if (!poTarget.LockOrbit)
{
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
poTarget.SetOrbit = (PlanetOrbit.Orbit)EditorGUILayout.EnumPopup("Set Orbit:", poTarget.SetOrbit);
EditorGUILayout.Space();
if (poTarget.SetOrbit == 0)
{
GUILayout.Label("Orbital Period x1 Earth Years");
poTarget.OrbitalPeriod = EditorGUILayout.FloatField("Orbital Period: ", poTarget.OrbitalPeriod);
}
else
{
GUILayout.Label("Orbital Period In Earth Time");
poTarget.OrbitYears = EditorGUILayout.FloatField("Orbit Years: ", poTarget.OrbitYears);
poTarget.OrbitDays = EditorGUILayout.FloatField("Orbit Days: ", poTarget.OrbitDays);
poTarget.OrbitHours = EditorGUILayout.FloatField("Orbit Hours: ", poTarget.OrbitHours);
poTarget.OrbitMinutes = EditorGUILayout.FloatField("Orbit Minutes: ", poTarget.OrbitMinutes);
poTarget.OrbitSeconds = EditorGUILayout.FloatField("Orbit Seconds: ", poTarget.OrbitSeconds);
}
}
//}else
//if(SetupPlanet == 1){
if (!poTarget.TidalLock)
{
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
GUILayout.Label("Planet Rotation ------------------------------", EditorStyles.boldLabel);
EditorGUILayout.Space();
poTarget.SetRotation = (PlanetOrbit.Rotation)EditorGUILayout.EnumPopup("Set Rotation:", poTarget.SetRotation);
EditorGUILayout.Space();
if (poTarget.SetRotation == 0)
{
GUILayout.Label("Rotation Period x1 Earth Days");
poTarget.RotationPeriod = EditorGUILayout.FloatField("Orbital Period: ", poTarget.OrbitalPeriod);
}
else
{
GUILayout.Label("Rotation Period In Earth Time");
poTarget.RotationYears = EditorGUILayout.IntField("Rotation Years: ", poTarget.RotationYears);
poTarget.RotationDays = EditorGUILayout.IntField("Rotation Days: ", poTarget.RotationDays);
poTarget.RotationHours = EditorGUILayout.IntField("Rotation Hours: ", poTarget.RotationHours);
poTarget.RotationMinutes = EditorGUILayout.IntField("Rotation Minutes: ", poTarget.RotationMinutes);
poTarget.RotationSeconds = EditorGUILayout.FloatField("Rotation Seconds: ", poTarget.RotationSeconds);
}
}
//}
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
if (!poTarget.LockOrbit)
{
GUILayout.Label("Local Planetary Statistics --------------------", EditorStyles.boldLabel);
EditorGUILayout.Space();
//GUILayout.Label("Allow Start Orbital Offset To Effect Year");
//poTarget.OrbitOffSetYear = EditorGUILayout.Toggle("Enabled:", poTarget.OrbitOffSetYear);
poTarget.CurrentOrbitPos = EditorGUILayout.Slider("Orbital Position: ", poTarget.CurrentOrbitPos, 0, 360);
EditorGUILayout.Space();
poTarget.KeepTime = EditorGUILayout.Toggle("Keep Local Time:", poTarget.KeepTime);
if (poTarget.KeepTime == true)
{
poTarget.CounterYear = EditorGUILayout.IntField(" Orbits: ", poTarget.CounterYear);
if (!poTarget.TidalLock)
{
poTarget.CounterDay = EditorGUILayout.IntField(" Rotations: ", poTarget.CounterDay);
EditorGUILayout.Space();
poTarget.RotInOrbit = EditorGUILayout.IntField(" Rotations Per Orbit: ", poTarget.RotInOrbit);
poTarget.HoursInDay = EditorGUILayout.IntField(" Hours Per Rotation: ", poTarget.HoursInDay);
EditorGUILayout.Space();
GUILayout.Label("Current Local Time");
poTarget.CounterHour = EditorGUILayout.IntField(" Hours: ", poTarget.CounterHour);
poTarget.CounterMinute = EditorGUILayout.IntField(" Minutes: ", poTarget.CounterMinute);
poTarget.CounterSecond = EditorGUILayout.FloatField(" Seconds: ", poTarget.CounterSecond);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment