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