No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FrameRateDrawer.cs 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Timeline;
  4. using TimelineEditorSettings = UnityEngine.Timeline.TimelineAsset.EditorSettings;
  5. #if TIMELINE_FRAMEACCURATE
  6. using UnityEngine.Playables;
  7. #endif
  8. namespace UnityEditor.Timeline
  9. {
  10. [CustomPropertyDrawer(typeof(FrameRateFieldAttribute), true)]
  11. class FrameRateDrawer : PropertyDrawer
  12. {
  13. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  14. {
  15. var frameRateAttribute = attribute as FrameRateFieldAttribute;
  16. if (frameRateAttribute == null)
  17. return;
  18. EditorGUI.BeginProperty(position, label, property);
  19. property.doubleValue = FrameRateField(property.doubleValue, label, position, out bool frameRateIsValid);
  20. EditorGUI.EndProperty();
  21. #if TIMELINE_FRAMEACCURATE
  22. if (!frameRateIsValid && TimelinePreferences.instance.playbackLockedToFrame)
  23. EditorGUILayout.HelpBox(
  24. L10n.Tr("Locking playback cannot be enabled for this frame rate."),
  25. MessageType.Warning);
  26. #endif
  27. }
  28. public static double FrameRateField(double frameRate, GUIContent label, Rect position, out bool isValid)
  29. {
  30. double frameRateDouble = FrameRateDisplayUtility.RoundFrameRate(frameRate);
  31. FrameRate frameRateObj = TimeUtility.GetClosestFrameRate(frameRateDouble);
  32. isValid = frameRateObj.IsValid();
  33. TimeUtility.ToStandardFrameRate(frameRateObj, out StandardFrameRates option);
  34. position = EditorGUI.PrefixLabel(position, label);
  35. Rect posPopup = new Rect(position.x, position.y, position.width / 2, position.height);
  36. Rect posFloatField = new Rect(posPopup.xMax, position.y, position.width / 2, position.height);
  37. using (var checkOption = new EditorGUI.ChangeCheckScope())
  38. {
  39. option = (StandardFrameRates)EditorGUI.Popup(posPopup, (int)option,
  40. FrameRateDisplayUtility.GetDefaultFrameRatesLabels(option));
  41. if (checkOption.changed)
  42. {
  43. isValid = true;
  44. return TimeUtility.ToFrameRate(option).rate;
  45. }
  46. }
  47. using (var checkFrame = new EditorGUI.ChangeCheckScope())
  48. {
  49. frameRateDouble = Math.Abs(EditorGUI.DoubleField(posFloatField, frameRateDouble));
  50. frameRateObj = TimeUtility.GetClosestFrameRate(frameRateDouble);
  51. if (checkFrame.changed)
  52. {
  53. isValid = frameRateObj.IsValid();
  54. return isValid ? frameRateObj.rate : frameRateDouble;
  55. }
  56. }
  57. return frameRateDouble;
  58. }
  59. }
  60. }