
Lyrics
[CustomPropertyDrawer(typeof(Controllable.DependencyType))]
public class DependencyRuleEnum : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var displayNames = property.enumNames.Select(ObjectNames.NicifyVariableName).ToArray();
var nameOfParentObject = RemoveFromLastDot(property.propertyPath);
if (property.serializedObject.FindProperty(nameOfParentObject).boxedValue is Controllable.DependencyRule dependencyRule && dependencyRule.Dependency)
{
displayNames = dependencyRule.Dependency.DependencyTypeDisplayNames;
}
property.enumValueIndex = EditorGUI.Popup(position, label.text, property.enumValueIndex, displayNames);
}
private static string RemoveFromLastDot(string x, string separator = ".")
{
var p = x.LastIndexOf(separator, StringComparison.Ordinal);
return p <= 0 ? x : x.Substring(0, p);
}
}