TimeReferenceUtility.cs
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using UnityEngine.Timeline;
namespace UnityEditor.Timeline
{
static class TimeReferenceUtility
{
static WindowState state { get { return TimelineWindow.instance.state; } }
public static double SnapToFrame(double time)
{
if (state.timeReferenceMode == TimeReferenceMode.Global)
{
time = state.editSequence.ToGlobalTime(time);
time = TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate);
return state.editSequence.ToLocalTime(time);
}
return TimeUtility.RoundToFrame(time, state.referenceSequence.frameRate);
}
public static string ToTimeString(double time, string format = "F2")
{
if (state.timeReferenceMode == TimeReferenceMode.Global)
time = state.editSequence.ToGlobalTime(time);
return state.editSequence.viewModel.timeInFrames ?
TimeUtility.TimeAsFrames(time, state.referenceSequence.frameRate, format) :
TimeUtility.TimeAsTimeCode(time, state.referenceSequence.frameRate, format);
}
public static double FromTimeString(string timeString)
{
double newTime;
if (state.timeInFrames)
{
double newFrameDouble;
if (double.TryParse(timeString, out newFrameDouble))
newTime = TimeUtility.FromFrames(newFrameDouble, state.referenceSequence.frameRate);
else
newTime = state.editSequence.time;
}
else
{
newTime = TimeUtility.ParseTimeCode(timeString, state.referenceSequence.frameRate, -1);
}
if (newTime >= 0.0)
{
return state.timeReferenceMode == TimeReferenceMode.Global ?
state.editSequence.ToLocalTime(newTime) : newTime;
}
return state.editSequence.time;
}
}
}