TimelineAssetInspector.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. using UnityEngine.Timeline;
  3. namespace UnityEditor.Timeline
  4. {
  5. [CustomEditor(typeof(TimelineAsset)), CanEditMultipleObjects]
  6. class TimelineAssetInspector : Editor
  7. {
  8. static class Styles
  9. {
  10. public static readonly GUIContent FrameRate = EditorGUIUtility.TrTextContent("Frame Rate", "The frame rate at which this sequence updates");
  11. public static readonly GUIContent DurationMode = EditorGUIUtility.TrTextContent("Duration Mode", "Specified how the duration of the sequence is calculated");
  12. public static readonly GUIContent Duration = EditorGUIUtility.TrTextContent("Duration", "The length of the sequence");
  13. public static readonly GUIContent HeaderTitleMultiselection = EditorGUIUtility.TrTextContent("Timeline Assets");
  14. }
  15. SerializedProperty m_FrameRateProperty;
  16. SerializedProperty m_DurationModeProperty;
  17. SerializedProperty m_FixedDurationProperty;
  18. void InitializeProperties()
  19. {
  20. m_FrameRateProperty = serializedObject.FindProperty("m_EditorSettings").FindPropertyRelative("m_Framerate");
  21. m_DurationModeProperty = serializedObject.FindProperty("m_DurationMode");
  22. m_FixedDurationProperty = serializedObject.FindProperty("m_FixedDuration");
  23. }
  24. public void OnEnable()
  25. {
  26. InitializeProperties();
  27. }
  28. internal override bool IsEnabled()
  29. {
  30. return !FileUtil.HasReadOnly(targets) && base.IsEnabled();
  31. }
  32. protected override void OnHeaderGUI()
  33. {
  34. string headerTitle;
  35. if (targets.Length == 1)
  36. headerTitle = target.name;
  37. else
  38. headerTitle = targets.Length.ToString() + " " + Styles.HeaderTitleMultiselection.text;
  39. DrawHeaderGUI(this, headerTitle, 0);
  40. }
  41. public override void OnInspectorGUI()
  42. {
  43. serializedObject.Update();
  44. EditorGUI.BeginChangeCheck();
  45. EditorGUILayout.PropertyField(m_FrameRateProperty, Styles.FrameRate, GUILayout.MinWidth(140));
  46. var frameRate = m_FrameRateProperty.doubleValue;
  47. EditorGUILayout.PropertyField(m_DurationModeProperty, Styles.DurationMode, GUILayout.MinWidth(140));
  48. var durationMode = (TimelineAsset.DurationMode)m_DurationModeProperty.enumValueIndex;
  49. var inputEvent = InputEvent.None;
  50. if (durationMode == TimelineAsset.DurationMode.FixedLength)
  51. TimelineInspectorUtility.TimeField(m_FixedDurationProperty, Styles.Duration, false, frameRate, double.Epsilon, TimelineClip.kMaxTimeValue * 2, ref inputEvent);
  52. else
  53. {
  54. var isMixed = targets.Length > 1;
  55. TimelineInspectorUtility.TimeField(Styles.Duration, ((TimelineAsset)target).duration, true, isMixed, frameRate, double.MinValue, double.MaxValue, ref inputEvent);
  56. }
  57. bool changed = EditorGUI.EndChangeCheck();
  58. serializedObject.ApplyModifiedProperties();
  59. if (changed)
  60. TimelineWindow.RepaintIfEditingTimelineAsset((TimelineAsset)target);
  61. }
  62. }
  63. }