A game about forced loneliness, made by TACStudios
at master 62 lines 2.1 kB view raw
1using UnityEngine; 2using UnityEngine.Timeline; 3 4namespace UnityEditor.Timeline 5{ 6 static class TimeReferenceUtility 7 { 8 static WindowState state { get { return TimelineWindow.instance.state; } } 9 10 public static float PixelToTime(Vector2 mousePos) 11 { 12 return PixelToTime(mousePos.x); 13 } 14 15 public static float PixelToTime(float pixelX) 16 { 17 return state.PixelToTime(pixelX); 18 } 19 20 public static double GetSnappedTimeAtMousePosition(Vector2 mousePos) 21 { 22 return state.GetSnappedTimeAtMousePosition(mousePos); 23 } 24 25 public static double SnapToFrameIfRequired(double currentTime) 26 { 27 return TimelinePreferences.instance.snapToFrame ? SnapToFrame(currentTime) : currentTime; 28 } 29 30 public static double SnapToFrame(double time) 31 { 32 if (state.timeReferenceMode == TimeReferenceMode.Global) 33 { 34 time = state.editSequence.ToGlobalTime(time); 35 time = TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate); 36 return state.editSequence.ToLocalTime(time); 37 } 38 39 return TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate); 40 } 41 42 public static string ToTimeString(double time, string format = "F2") 43 { 44 if (state.timeReferenceMode == TimeReferenceMode.Global) 45 time = state.editSequence.ToGlobalTime(time); 46 47 return state.timeFormat.ToTimeString(time, state.referenceSequence.frameRate, format); 48 } 49 50 public static double FromTimeString(string timeString) 51 { 52 double newTime = state.timeFormat.FromTimeString(timeString, state.referenceSequence.frameRate, -1); 53 if (newTime >= 0.0) 54 { 55 return state.timeReferenceMode == TimeReferenceMode.Global ? 56 state.editSequence.ToLocalTime(newTime) : newTime; 57 } 58 59 return state.editSequence.time; 60 } 61 } 62}