88 lines
3.1 KiB
C#
88 lines
3.1 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 somethingChanged = false;
|
|
|
|
GUIStyle foldoutStyle = new(EditorStyles.foldout) {
|
|
margin = EditorStyles.objectField.margin
|
|
};
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
string legName = ConvertCamelCase(legProp.name);
|
|
showfield = EditorGUILayout.Foldout(showfield, legName, true, foldoutStyle);
|
|
bool femurChanged = FemurInspector(leg);
|
|
if (femurChanged) {
|
|
Debug.Log("Check");
|
|
leg.DetectBones(leg.femur);
|
|
}
|
|
somethingChanged |= femurChanged;
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
if (leg.femur != null && leg.tibia == null)
|
|
showfield = true;
|
|
|
|
if (showfield) {
|
|
EditorGUI.indentLevel++;
|
|
somethingChanged |= TibiaInspector(leg);
|
|
somethingChanged |= TarsusInspector(leg);
|
|
somethingChanged |= PhalangesInspector(leg);
|
|
EditorGUI.indentLevel--;
|
|
}
|
|
return somethingChanged;
|
|
}
|
|
|
|
protected static bool FemurInspector(Leg leg) {
|
|
Transform oldFemur = leg.femur;
|
|
leg.femur = (Transform)EditorGUILayout.ObjectField(leg.femur, typeof(Transform), true);
|
|
return leg.femur != oldFemur;
|
|
}
|
|
|
|
protected static bool TibiaInspector(Leg leg) {
|
|
Transform oldTibia = leg.tibia;
|
|
leg.tibia = (Transform)EditorGUILayout.ObjectField("Lower leg", leg.tibia, typeof(Transform), true);
|
|
return leg.tibia != oldTibia;
|
|
}
|
|
|
|
protected static bool TarsusInspector(Leg leg) {
|
|
Transform oldTarsus = leg.tarsus;
|
|
leg.tarsus = (Transform)EditorGUILayout.ObjectField("Foot", leg.tarsus, typeof(Transform), true);
|
|
return leg.tarsus != oldTarsus;
|
|
}
|
|
|
|
protected static bool PhalangesInspector(Leg leg) {
|
|
Transform oldPhalanges = leg.phalanges;
|
|
leg.phalanges = (Transform)EditorGUILayout.ObjectField("Toes", leg.phalanges, typeof(Transform), true);
|
|
return leg.phalanges != oldPhalanges;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
} |