SpineAnimationStateDrawer.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated April 5, 2025. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2025, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. using Spine.Unity.Editor;
  30. using Spine.Unity.Playables;
  31. using UnityEditor;
  32. using UnityEngine;
  33. [CustomPropertyDrawer(typeof(SpineAnimationStateBehaviour))]
  34. public class SpineAnimationStateDrawer : PropertyDrawer {
  35. public override float GetPropertyHeight (SerializedProperty property, GUIContent label) {
  36. const int fieldCount = 16;
  37. return fieldCount * EditorGUIUtility.singleLineHeight;
  38. }
  39. public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
  40. SerializedProperty animationReferenceProp = property.FindPropertyRelative("animationReference");
  41. SerializedProperty loopProp = property.FindPropertyRelative("loop");
  42. SerializedProperty customDurationProp = property.FindPropertyRelative("customDuration");
  43. SerializedProperty useBlendDurationProp = property.FindPropertyRelative("useBlendDuration");
  44. SerializedProperty mixDurationProp = property.FindPropertyRelative("mixDuration");
  45. SerializedProperty holdPreviousProp = property.FindPropertyRelative("holdPrevious");
  46. SerializedProperty alphaProp = property.FindPropertyRelative("alpha");
  47. SerializedProperty dontPauseWithDirectorProp = property.FindPropertyRelative("dontPauseWithDirector");
  48. SerializedProperty dontEndWithClip = property.FindPropertyRelative("dontEndWithClip");
  49. SerializedProperty endMixOutDuration = property.FindPropertyRelative("endMixOutDuration");
  50. SerializedProperty eventProp = property.FindPropertyRelative("eventThreshold");
  51. SerializedProperty attachmentProp = property.FindPropertyRelative("attachmentThreshold");
  52. SerializedProperty drawOrderProp = property.FindPropertyRelative("drawOrderThreshold");
  53. // initialize customDuration (inverse default mix duration) and useBlendDuration parameters according to preferences
  54. SerializedProperty isInitializedProp = property.FindPropertyRelative("isInitialized");
  55. if (!isInitializedProp.hasMultipleDifferentValues && isInitializedProp.boolValue == false) {
  56. customDurationProp.boolValue = !SpineEditorUtilities.Preferences.timelineDefaultMixDuration;
  57. useBlendDurationProp.boolValue = SpineEditorUtilities.Preferences.timelineUseBlendDuration;
  58. isInitializedProp.boolValue = true;
  59. }
  60. Rect singleFieldRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
  61. float lineHeightWithSpacing = EditorGUIUtility.singleLineHeight + 2f;
  62. EditorGUI.PropertyField(singleFieldRect, animationReferenceProp);
  63. singleFieldRect.y += lineHeightWithSpacing;
  64. EditorGUI.PropertyField(singleFieldRect, loopProp);
  65. singleFieldRect.y += lineHeightWithSpacing;
  66. EditorGUI.PropertyField(singleFieldRect, dontPauseWithDirectorProp,
  67. new GUIContent("Don't Pause with Director",
  68. "If set to true, the animation will continue playing when the Director is paused."));
  69. singleFieldRect.y += lineHeightWithSpacing;
  70. EditorGUI.PropertyField(singleFieldRect, dontEndWithClip,
  71. new GUIContent("Don't End with Clip",
  72. "Normally when empty space follows the clip on the timeline, the empty animation is set on the track. " +
  73. "Set this parameter to true to continue playing the clip's animation instead."));
  74. singleFieldRect.y += lineHeightWithSpacing;
  75. using (new EditorGUI.DisabledGroupScope(dontEndWithClip.boolValue == true)) {
  76. EditorGUI.PropertyField(singleFieldRect, endMixOutDuration,
  77. new GUIContent("Clip End Mix Out Duration",
  78. "When 'Don't End with Clip' is false, and the clip is followed by blank space or stopped, " +
  79. "the empty animation is set with this MixDuration. When set to a negative value, " +
  80. "the clip is paused instead."));
  81. }
  82. singleFieldRect.y += lineHeightWithSpacing * 0.5f;
  83. singleFieldRect.y += lineHeightWithSpacing;
  84. EditorGUI.LabelField(singleFieldRect, "Mixing Settings", EditorStyles.boldLabel);
  85. singleFieldRect.y += lineHeightWithSpacing;
  86. customDurationProp.boolValue = !EditorGUI.Toggle(singleFieldRect,
  87. new GUIContent("Default Mix Duration",
  88. "Use the default mix duration as specified at the SkeletonDataAsset."),
  89. !customDurationProp.boolValue);
  90. bool greyOutCustomDurations = (!customDurationProp.hasMultipleDifferentValues &&
  91. customDurationProp.boolValue == false);
  92. using (new EditorGUI.DisabledGroupScope(greyOutCustomDurations)) {
  93. singleFieldRect.y += lineHeightWithSpacing;
  94. EditorGUI.PropertyField(singleFieldRect, useBlendDurationProp);
  95. singleFieldRect.y += lineHeightWithSpacing;
  96. bool greyOutMixDuration = (!useBlendDurationProp.hasMultipleDifferentValues &&
  97. useBlendDurationProp.boolValue == true);
  98. using (new EditorGUI.DisabledGroupScope(greyOutMixDuration)) {
  99. EditorGUI.PropertyField(singleFieldRect, mixDurationProp);
  100. }
  101. }
  102. singleFieldRect.y += lineHeightWithSpacing;
  103. EditorGUI.PropertyField(singleFieldRect, holdPreviousProp);
  104. singleFieldRect.y += lineHeightWithSpacing;
  105. EditorGUI.PropertyField(singleFieldRect, eventProp);
  106. singleFieldRect.y += lineHeightWithSpacing;
  107. EditorGUI.PropertyField(singleFieldRect, attachmentProp);
  108. singleFieldRect.y += lineHeightWithSpacing;
  109. EditorGUI.PropertyField(singleFieldRect, drawOrderProp);
  110. singleFieldRect.y += lineHeightWithSpacing;
  111. EditorGUI.PropertyField(singleFieldRect, alphaProp);
  112. }
  113. }