Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AnimationTriggersDrawer.cs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEditor.UIElements;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.UI
  6. {
  7. [CustomPropertyDrawer(typeof(AnimationTriggers), true)]
  8. /// <summary>
  9. /// This is a PropertyDrawer for AnimationTriggers. It is implemented using the standard Unity PropertyDrawer framework.
  10. /// </summary>
  11. public class AnimationTriggersDrawer : PropertyDrawer
  12. {
  13. const string kNormalTrigger = "m_NormalTrigger";
  14. const string kHighlightedTrigger = "m_HighlightedTrigger";
  15. const string kPressedTrigger = "m_PressedTrigger";
  16. const string kSelectedTrigger = "m_SelectedTrigger";
  17. const string kDisabledTrigger = "m_DisabledTrigger";
  18. public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
  19. {
  20. Rect drawRect = rect;
  21. drawRect.height = EditorGUIUtility.singleLineHeight;
  22. SerializedProperty normalTrigger = prop.FindPropertyRelative(kNormalTrigger);
  23. SerializedProperty higlightedTrigger = prop.FindPropertyRelative(kHighlightedTrigger);
  24. SerializedProperty pressedTrigger = prop.FindPropertyRelative(kPressedTrigger);
  25. SerializedProperty selectedTrigger = prop.FindPropertyRelative(kSelectedTrigger);
  26. SerializedProperty disabledTrigger = prop.FindPropertyRelative(kDisabledTrigger);
  27. EditorGUI.PropertyField(drawRect, normalTrigger);
  28. drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
  29. EditorGUI.PropertyField(drawRect, higlightedTrigger);
  30. drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
  31. EditorGUI.PropertyField(drawRect, pressedTrigger);
  32. drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
  33. EditorGUI.PropertyField(drawRect, selectedTrigger);
  34. drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
  35. EditorGUI.PropertyField(drawRect, disabledTrigger);
  36. }
  37. public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
  38. {
  39. return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
  40. }
  41. public override VisualElement CreatePropertyGUI(SerializedProperty property)
  42. {
  43. var container = new VisualElement();
  44. var properties = new[]
  45. {
  46. property.FindPropertyRelative(kNormalTrigger),
  47. property.FindPropertyRelative(kHighlightedTrigger),
  48. property.FindPropertyRelative(kPressedTrigger),
  49. property.FindPropertyRelative(kSelectedTrigger),
  50. property.FindPropertyRelative(kDisabledTrigger),
  51. };
  52. foreach (var prop in properties)
  53. {
  54. var field = new PropertyField(prop);
  55. container.Add(field);
  56. }
  57. return container;
  58. }
  59. }
  60. }