AnimatorParameterDrawer.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #if UNITY_EDITOR
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace GpuEcsAnimationBaker.Engine.Data
  5. {
  6. [CustomPropertyDrawer(typeof(AnimatorParameter))]
  7. public class AnimatorParameterDrawer : PropertyDrawer
  8. {
  9. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  10. {
  11. EditorGUI.BeginProperty(position, label, property);
  12. float w = (position.width - 90) / 2;
  13. SerializedProperty parameterNameProperty = property.FindPropertyRelative("parameterName");
  14. SerializedProperty parameterTypeProperty = property.FindPropertyRelative("parameterType");
  15. SerializedProperty boolValueProperty = property.FindPropertyRelative("boolValue");
  16. SerializedProperty floatValueProperty = property.FindPropertyRelative("floatValue");
  17. SerializedProperty intValueProperty = property.FindPropertyRelative("intValue");
  18. EditorGUI.PropertyField(new Rect(position.position, new Vector2(w, position.height)),
  19. parameterNameProperty, new GUIContent(""));
  20. EditorGUI.BeginChangeCheck();
  21. EditorGUI.PropertyField(new Rect(position.position + new Vector2(w + 5, 0), new Vector2(80, position.height)),
  22. parameterTypeProperty, new GUIContent(""));
  23. if (EditorGUI.EndChangeCheck())
  24. {
  25. boolValueProperty.boolValue = false;
  26. floatValueProperty.floatValue = 0;
  27. intValueProperty.intValue = 0;
  28. }
  29. AnimatorParameterTypes parameterType = (AnimatorParameterTypes)parameterTypeProperty.enumValueIndex;
  30. SerializedProperty valueProperty = null;
  31. if (parameterType == AnimatorParameterTypes.Bool) valueProperty = boolValueProperty;
  32. else if (parameterType == AnimatorParameterTypes.Float) valueProperty = floatValueProperty;
  33. else if (parameterType == AnimatorParameterTypes.Integer) valueProperty = intValueProperty;
  34. EditorGUI.PropertyField(new Rect(position.position + new Vector2(w + 90, 0), new Vector2(w, position.height)),
  35. valueProperty, new GUIContent(""));
  36. EditorGUI.EndProperty();
  37. }
  38. }
  39. }
  40. #endif