Files
project-reset/Assets/Scripts/Core/ValueGroupEditors.cs

482 lines
17 KiB
C#

using NodeCanvas.Editor;
using ParadoxNotion.Design;
using Reset.Core;
using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
public class BoolValueGroupDrawer : ObjectDrawer<BoolValueGroup> {
public override BoolValueGroup OnGUI(GUIContent _content, BoolValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(80.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(200.0f),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, labelOptions);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeValue = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue){
_instance.value = EditorGUILayout.Toggle(_instance.value.value, floatOptions);
} else if (_instance.changeValue.value == ValueChangeAction.RelativeValue){
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField("Not Available", floatOptions);
EditorGUI.EndDisabledGroup();
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeValue.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class CurveValueGroupDrawer : ObjectDrawer<CurveValueGroup> {
public override CurveValueGroup OnGUI(GUIContent _content, CurveValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(80.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(200.0f),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, labelOptions);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeValue.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue){
BBParameterEditor.ParameterField("", _instance.value);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeValue.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class EnumValueGroupDrawer : ObjectDrawer<EnumValueGroup>{
public override EnumValueGroup OnGUI(GUIContent _content, EnumValueGroup _instance){
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(200.0f),
GUILayout.MinWidth(100.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(200.0f),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, labelOptions);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeValue.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue){
_instance.value.value = EditorGUILayout.EnumPopup("", instance.value.value, floatOptions);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField((ValueChangeAction)_instance.value.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class FloatValueGroupDrawer : ObjectDrawer<FloatValueGroup> {
public override FloatValueGroup OnGUI(GUIContent _content, FloatValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// Start the label
GUILayout.BeginHorizontal();
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(80.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(200.0f),
};
GUIStyle titleText = new GUIStyle{
fontSize = 12,
fontStyle = FontStyle.Bold,
padding = new RectOffset(8, 0, 3,0),
normal ={
textColor = Color.white
}
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.Label(_instance.label, titleText);
// End the label
GUILayout.EndHorizontal();
// Start the variables
GUILayout.BeginHorizontal();
// Create the x settings enum
// _instance.changeValue.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue.value);
BBParameterEditor.ParameterField("", _instance.changeValue);
// Create the value/disabled information field
if (_instance.changeValue.value == ValueChangeAction.NewValue || _instance.changeValue.value == ValueChangeAction.RelativeValue){
BBParameterEditor.ParameterField("", _instance.value);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeValue.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up with the variables
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class Vector3ValueGroupDrawer : ObjectDrawer<Vector3ValueGroup> {
public override Vector3ValueGroup OnGUI(GUIContent _content, Vector3ValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 20;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(300.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(200.0f),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, labelOptions);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeX.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeX.value);
// Create the value/disabled information field
if (_instance.changeX.value== ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.x = EditorGUILayout.FloatField(_instance.value.value.x, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeX.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the y settings enum
_instance.changeY.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeY.value);
// Create the value/disabled information field
if (_instance.changeY.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.y = EditorGUILayout.FloatField(_instance.value.value.y, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeY.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the y settings enum
_instance.changeZ.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeZ.value);
// Create the value/disabled information field
if (_instance.changeZ.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.z = EditorGUILayout.FloatField(_instance.value.value.z, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeZ.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public class Vector2ValueGroupDrawer : ObjectDrawer<Vector2ValueGroup> {
public override Vector2ValueGroup OnGUI(GUIContent _content, Vector2ValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(300.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(200.0f),
};
// Start the Vertical layout then add the label before adding a horizontal so the label will be on top of side-by-side options
GUILayout.BeginVertical();
GUILayout.Label(_instance.label, labelOptions);
GUILayout.BeginHorizontal();
// Create the x settings enum
_instance.changeX.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeX.value);
// Create the value/disabled information field
if (_instance.changeX.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.x = EditorGUILayout.FloatField(_instance.value.value.x, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeX.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the y settings enum
_instance.changeY.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeY.value);
// Create the value/disabled information field
if (_instance.changeY.value == ValueChangeAction.NewValue) {
var value = _instance.value.value;
value.y = EditorGUILayout.FloatField(_instance.value.value.y, floatOptions);
_instance.value.value = value;
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeY.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
GUILayout.EndVertical();
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
// Custom editor for each orbital follow ring setting
public class OrbitalFollowValueGroupDrawer : ObjectDrawer<OrbitalFollowValueGroup>{
public override OrbitalFollowValueGroup OnGUI(GUIContent _content, OrbitalFollowValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 1;
// Set layout options for the label and the float fields
GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(300.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
GUILayoutOption[] labelOptions = new GUILayoutOption[]{
GUILayout.Width(60.0f),
};
// Start a Horiztonal Section
GUILayout.BeginHorizontal();
// Add the left side label
GUILayout.Label(_instance.label, labelOptions);
// Create the height settings enum
_instance.changeHeight.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeHeight.value);
// Create the value/disabled information field
if (_instance.changeHeight.value == ValueChangeAction.NewValue){
_instance.height.value = EditorGUILayout.FloatField(_instance.height.value, floatOptions);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeHeight.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// It do what it do.
GUILayout.Space(5);
// Create the radius settings enum
_instance.changeRadius.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", _instance.changeRadius.value);
// Create the value/disabled information field
if (_instance.changeRadius.value == ValueChangeAction.NewValue){
_instance.radius = EditorGUILayout.FloatField(_instance.radius.value, floatOptions);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeRadius.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close this line up
GUILayout.EndHorizontal();
ValueGroupEditorUtilities.DrawEasingAndSmoothingSection(_instance);
// Reset to default so the rest of things don't get messed up
EditorGUIUtility.labelWidth = 0;
return _instance;
}
}
public static class ValueGroupEditorUtilities{
public static void DrawEasingAndSmoothingSection(ValueGroup.ISmoothable _instance){
// Start the smoothing and easing section
GUILayout.BeginHorizontal();
GUIStyle smallText= new GUIStyle{
fontSize = 10,
padding = new RectOffset(8, 0, 0,0),
normal ={
textColor = Color.gray
}
};
// Start the left side for easing
GUILayout.BeginVertical();
// Draw the label
GUILayout.BeginHorizontal();
GUILayout.Label("Easing", smallText);
GUILayout.EndHorizontal();
// Easing
// _instance.changeEasing.value = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeEasing.value);
BBParameterEditor.ParameterField("", _instance.changeEasing);
if (_instance.changeEasing.value == ValueChangeAction.NewValue){
// _instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
BBParameterEditor.ParameterField("", _instance.Easing);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeEasing.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close easing
GUILayout.EndVertical();
// Start the right for smoothing
GUILayout.BeginVertical();
// Draw the label
GUILayout.BeginHorizontal();
GUILayout.Label("Smoothing", smallText);
GUILayout.EndHorizontal();
// Smoothing
BBParameterEditor.ParameterField("", _instance.changeSmoothing);
if (_instance.changeSmoothing.value == ValueChangeAction.NewValue){
// _instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
BBParameterEditor.ParameterField("", _instance.Smoothing);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeSmoothing.value == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);
EditorGUI.EndDisabledGroup();
}
// Close easing
GUILayout.EndVertical();
GUILayout.Space(8);
GUILayout.EndHorizontal();
}
static GUILayoutOption[] floatOptions = new GUILayoutOption[] {
GUILayout.Width(300.0f),
GUILayout.MinWidth(20.0f),
GUILayout.ExpandWidth(true),
};
}
#endif