SideSlipDeviceGuideEntryPropertyDrawer.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #if UNITY_EDITOR
  2. using AppUI.View.Component;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace AppUI.Editor
  6. {
  7. [CustomPropertyDrawer(typeof(SideSlipDeviceGuideEntry))]
  8. public class SideSlipDeviceGuideEntryPropertyDrawer : PropertyDrawer
  9. {
  10. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  11. {
  12. return EditorGUI.GetPropertyHeight(property, GetEntryLabel(property), true);
  13. }
  14. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  15. {
  16. EditorGUI.PropertyField(position, property, GetEntryLabel(property), true);
  17. }
  18. static GUIContent GetEntryLabel(SerializedProperty property)
  19. {
  20. SerializedProperty deviceTypeProp = property.FindPropertyRelative("deviceType");
  21. if (deviceTypeProp == null)
  22. return new GUIContent(property.displayName);
  23. var deviceType = (AimDeviceType)deviceTypeProp.intValue;
  24. string typeName = deviceType.ToString();
  25. return new GUIContent(typeName, $"Guide entry for {typeName}");
  26. }
  27. }
  28. }
  29. #endif