67 lines
2.7 KiB
C#

using UnityEditor;
using UnityEngine;
namespace CreatureControl {
public class Leg_Editor {
private static bool showfield = false;
public static bool Inspector(SerializedProperty legProp, TargetLeg targetLeg, Leg leg) {
bool anythingChanged = false;
GUIStyle foldoutStyle = new(EditorStyles.foldout) {
margin = EditorStyles.objectField.margin
};
EditorGUILayout.BeginHorizontal();
string legName = ConvertCamelCase(legProp.name);
showfield = EditorGUILayout.Foldout(showfield, legName, true, foldoutStyle);
SerializedProperty femurProp = legProp.FindPropertyRelative("_femur");//nameof(Leg._femur));
SerializedProperty tibiaProp = legProp.FindPropertyRelative("_tibia"); //nameof(Leg._tibia));
SerializedProperty tarsusProp = legProp.FindPropertyRelative("_tarsus"); //nameof(Leg._tarsus));
Transform newFemur = (Transform)EditorGUILayout.ObjectField(femurProp.objectReferenceValue, typeof(Transform), true);
if (newFemur != femurProp.objectReferenceValue) {
leg.DetectBones(newFemur);
anythingChanged = true;
}
EditorGUILayout.EndHorizontal();
if (femurProp.objectReferenceValue != null && tibiaProp.objectReferenceValue == null)
showfield = true;
if (showfield) {
EditorGUI.indentLevel++;
tibiaProp.objectReferenceValue = (Transform)EditorGUILayout.ObjectField("Lower Leg", tibiaProp.objectReferenceValue, typeof(Transform), true);
tarsusProp.objectReferenceValue = (Transform)EditorGUILayout.ObjectField("Foot", tarsusProp.objectReferenceValue, typeof(Transform), true);
// Need to check if anythingChanged and update the projection if it did
EditorGUI.indentLevel--;
}
return anythingChanged;
}
private static string ConvertCamelCase(string text) {
if (string.IsNullOrEmpty(text))
return text;
System.Text.StringBuilder result = new();
for (int i = 0; i < text.Length; i++) {
// Add a space before uppercase characters
if (char.IsUpper(text[i]) && i > 0)
result.Append(' ');
// Add the character to the result
result.Append(text[i]);
}
// Capitalize the first character of the result
if (result.Length > 0)
result[0] = char.ToUpper(result[0]);
return result.ToString();
}
}
}