TransformTweenDrawer.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CustomPropertyDrawer(typeof(TransformTweenBehaviour))]
  4. public class TransformTweenDrawer : PropertyDrawer
  5. {
  6. GUIContent m_TweenPositionContent = new GUIContent("Tween Position", "This should be true if the transformToMove to change position. This causes recalulations each frame which are more CPU intensive.");
  7. GUIContent m_TweenRotationContent = new GUIContent("Tween Rotation", "This should be true if the transformToMove to change rotation.");
  8. GUIContent m_TweenTypeContent = new GUIContent("Tween Type", "Linear - the transform moves the same amount each frame (assuming static start and end locations).\n"
  9. + "Deceleration - the transform moves slower the closer to the end location it is.\n"
  10. + "Harmonic - the transform moves faster in the middle of its tween.\n"
  11. + "Custom - uses the customStartingSpeed and customEndingSpeed to create a curve for the desired tween.");
  12. GUIContent m_CustomCurveContent = new GUIContent("Custom Curve", "This should be a normalised curve (between 0,0 and 1,1) that represents how the tweening object accelerates at different points along the clip.");
  13. public override float GetPropertyHeight (SerializedProperty property, GUIContent label)
  14. {
  15. int fieldCount = property.FindPropertyRelative ("tweenType").enumValueIndex == (int)TransformTweenBehaviour.TweenType.Custom ? 5 : 3;
  16. return fieldCount * (EditorGUIUtility.singleLineHeight);
  17. }
  18. public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
  19. {
  20. SerializedProperty tweenPositionProp = property.FindPropertyRelative ("tweenPosition");
  21. SerializedProperty tweenRotationProp = property.FindPropertyRelative("tweenRotation");
  22. SerializedProperty tweenTypeProp = property.FindPropertyRelative ("tweenType");
  23. Rect singleFieldRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
  24. EditorGUI.PropertyField (singleFieldRect, tweenPositionProp, m_TweenPositionContent);
  25. singleFieldRect.y += EditorGUIUtility.singleLineHeight;
  26. EditorGUI.PropertyField (singleFieldRect, tweenRotationProp, m_TweenRotationContent);
  27. singleFieldRect.y += EditorGUIUtility.singleLineHeight;
  28. EditorGUI.PropertyField(singleFieldRect, tweenTypeProp, m_TweenTypeContent);
  29. if (tweenTypeProp.enumValueIndex == (int)TransformTweenBehaviour.TweenType.Custom)
  30. {
  31. SerializedProperty customCurveProp = property.FindPropertyRelative ("customCurve");
  32. singleFieldRect.y += EditorGUIUtility.singleLineHeight;
  33. EditorGUI.PropertyField (singleFieldRect, customCurveProp, m_CustomCurveContent);
  34. }
  35. }
  36. }