SpineAnimationStateDrawer.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated May 1, 2019. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2019, 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. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
  19. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  21. * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
  24. * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  27. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. using UnityEditor;
  30. using UnityEngine;
  31. using Spine;
  32. using Spine.Unity;
  33. using Spine.Unity.Playables;
  34. using Spine.Unity.Editor;
  35. [CustomPropertyDrawer(typeof(SpineAnimationStateBehaviour))]
  36. public class SpineAnimationStateDrawer : PropertyDrawer {
  37. public override float GetPropertyHeight (SerializedProperty property, GUIContent label) {
  38. const int fieldCount = 10;
  39. return fieldCount * EditorGUIUtility.singleLineHeight;
  40. }
  41. public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
  42. SerializedProperty animationReferenceProp = property.FindPropertyRelative("animationReference");
  43. SerializedProperty loopProp = property.FindPropertyRelative("loop");
  44. SerializedProperty customDurationProp = property.FindPropertyRelative("customDuration");
  45. SerializedProperty useBlendDurationProp = property.FindPropertyRelative("useBlendDuration");
  46. SerializedProperty mixDurationProp = property.FindPropertyRelative("mixDuration");
  47. SerializedProperty eventProp = property.FindPropertyRelative("eventThreshold");
  48. SerializedProperty attachmentProp = property.FindPropertyRelative("attachmentThreshold");
  49. SerializedProperty drawOrderProp = property.FindPropertyRelative("drawOrderThreshold");
  50. // initialize useBlendDuration parameter according to preferences
  51. SerializedProperty isInitializedProp = property.FindPropertyRelative("isInitialized");
  52. if (!isInitializedProp.hasMultipleDifferentValues && isInitializedProp.boolValue == false) {
  53. useBlendDurationProp.boolValue = SpineEditorUtilities.Preferences.timelineUseBlendDuration;
  54. isInitializedProp.boolValue = true;
  55. }
  56. Rect singleFieldRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
  57. float lineHeightWithSpacing = EditorGUIUtility.singleLineHeight + 2f;
  58. EditorGUI.PropertyField(singleFieldRect, animationReferenceProp);
  59. singleFieldRect.y += lineHeightWithSpacing;
  60. EditorGUI.PropertyField(singleFieldRect, loopProp);
  61. singleFieldRect.y += lineHeightWithSpacing * 0.5f;
  62. singleFieldRect.y += lineHeightWithSpacing;
  63. EditorGUI.LabelField(singleFieldRect, "Mixing Settings", EditorStyles.boldLabel);
  64. singleFieldRect.y += lineHeightWithSpacing;
  65. EditorGUI.PropertyField(singleFieldRect, customDurationProp);
  66. bool greyOutCustomDurations = (!customDurationProp.hasMultipleDifferentValues &&
  67. customDurationProp.boolValue == false);
  68. using (new EditorGUI.DisabledGroupScope(greyOutCustomDurations)) {
  69. singleFieldRect.y += lineHeightWithSpacing;
  70. EditorGUI.PropertyField(singleFieldRect, useBlendDurationProp);
  71. singleFieldRect.y += lineHeightWithSpacing;
  72. EditorGUI.PropertyField(singleFieldRect, mixDurationProp);
  73. }
  74. singleFieldRect.y += lineHeightWithSpacing;
  75. EditorGUI.PropertyField(singleFieldRect, eventProp);
  76. singleFieldRect.y += lineHeightWithSpacing;
  77. EditorGUI.PropertyField(singleFieldRect, attachmentProp);
  78. singleFieldRect.y += lineHeightWithSpacing;
  79. EditorGUI.PropertyField(singleFieldRect, drawOrderProp);
  80. }
  81. }