scripts
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace UnityEngine.Timeline
|
||||
{
|
||||
// Token: 0x02000040 RID: 64
|
||||
internal static class TimeUtility
|
||||
{
|
||||
// Token: 0x06000202 RID: 514 RVA: 0x0000A3A1 File Offset: 0x000085A1
|
||||
private static void ValidateFrameRate(double frameRate)
|
||||
{
|
||||
if (frameRate <= TimeUtility.kTimeEpsilon)
|
||||
{
|
||||
throw new ArgumentException("frame rate cannot be 0 or negative");
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06000203 RID: 515 RVA: 0x0000A3BC File Offset: 0x000085BC
|
||||
public static int ToFrames(double time, double frameRate)
|
||||
{
|
||||
TimeUtility.ValidateFrameRate(frameRate);
|
||||
double num = TimeUtility.kTimeEpsilon * time;
|
||||
int num2;
|
||||
if (time < 0.0)
|
||||
{
|
||||
num2 = (int)Math.Ceiling(time * frameRate + num);
|
||||
}
|
||||
else
|
||||
{
|
||||
num2 = (int)Math.Floor(time * frameRate + num);
|
||||
}
|
||||
return num2;
|
||||
}
|
||||
|
||||
// Token: 0x06000204 RID: 516 RVA: 0x0000A40C File Offset: 0x0000860C
|
||||
public static double ToExactFrames(double time, double frameRate)
|
||||
{
|
||||
TimeUtility.ValidateFrameRate(frameRate);
|
||||
return time * frameRate;
|
||||
}
|
||||
|
||||
// Token: 0x06000205 RID: 517 RVA: 0x0000A42C File Offset: 0x0000862C
|
||||
public static double FromFrames(int frames, double frameRate)
|
||||
{
|
||||
TimeUtility.ValidateFrameRate(frameRate);
|
||||
return (double)frames / frameRate;
|
||||
}
|
||||
|
||||
// Token: 0x06000206 RID: 518 RVA: 0x0000A44C File Offset: 0x0000864C
|
||||
public static double FromFrames(double frames, double frameRate)
|
||||
{
|
||||
TimeUtility.ValidateFrameRate(frameRate);
|
||||
return frames / frameRate;
|
||||
}
|
||||
|
||||
// Token: 0x06000207 RID: 519 RVA: 0x0000A46C File Offset: 0x0000866C
|
||||
public static bool OnFrameBoundary(double time, double frameRate)
|
||||
{
|
||||
return TimeUtility.OnFrameBoundary(time, frameRate, Math.Max(time, 1.0) * frameRate * TimeUtility.kTimeEpsilon);
|
||||
}
|
||||
|
||||
// Token: 0x06000208 RID: 520 RVA: 0x0000A4A0 File Offset: 0x000086A0
|
||||
public static bool OnFrameBoundary(double time, double frameRate, double epsilon)
|
||||
{
|
||||
TimeUtility.ValidateFrameRate(frameRate);
|
||||
double num = TimeUtility.ToExactFrames(time, frameRate);
|
||||
double num2 = Math.Round(num);
|
||||
return Math.Abs(num - num2) < epsilon;
|
||||
}
|
||||
|
||||
// Token: 0x06000209 RID: 521 RVA: 0x0000A4D8 File Offset: 0x000086D8
|
||||
public static string TimeAsFrames(double timeValue, double frameRate, string format = "F2")
|
||||
{
|
||||
string text;
|
||||
if (TimeUtility.OnFrameBoundary(timeValue, frameRate))
|
||||
{
|
||||
text = TimeUtility.ToFrames(timeValue, frameRate).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
text = TimeUtility.ToExactFrames(timeValue, frameRate).ToString(format);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// Token: 0x0600020A RID: 522 RVA: 0x0000A524 File Offset: 0x00008724
|
||||
public static string TimeAsTimeCode(double timeValue, double frameRate, string format = "F2")
|
||||
{
|
||||
TimeUtility.ValidateFrameRate(frameRate);
|
||||
int num = (int)Math.Abs(timeValue);
|
||||
int num2 = num / 3600;
|
||||
int num3 = num % 3600 / 60;
|
||||
int num4 = num % 60;
|
||||
string text = ((timeValue >= 0.0) ? string.Empty : "-");
|
||||
string text2;
|
||||
if (num2 > 0)
|
||||
{
|
||||
text2 = string.Concat(new object[]
|
||||
{
|
||||
num2,
|
||||
":",
|
||||
num3.ToString("D2"),
|
||||
":",
|
||||
num4.ToString("D2")
|
||||
});
|
||||
}
|
||||
else if (num3 > 0)
|
||||
{
|
||||
text2 = num3 + ":" + num4.ToString("D2");
|
||||
}
|
||||
else
|
||||
{
|
||||
text2 = num4.ToString();
|
||||
}
|
||||
int num5 = (int)Math.Floor(Math.Log10(frameRate) + 1.0);
|
||||
string text3 = (TimeUtility.ToFrames(timeValue, frameRate) - TimeUtility.ToFrames((double)num, frameRate)).ToString().PadLeft(num5, '0');
|
||||
if (!TimeUtility.OnFrameBoundary(timeValue, frameRate))
|
||||
{
|
||||
string text4 = TimeUtility.ToExactFrames(timeValue, frameRate).ToString(format);
|
||||
int num6 = text4.IndexOf('.');
|
||||
if (num6 >= 0)
|
||||
{
|
||||
text3 = text3 + " [" + text4.Substring(num6) + "]";
|
||||
}
|
||||
}
|
||||
return text + text2 + ":" + text3;
|
||||
}
|
||||
|
||||
// Token: 0x0600020B RID: 523 RVA: 0x0000A6AC File Offset: 0x000088AC
|
||||
public static double ParseTimeCode(string timeCode, double frameRate, double defaultValue)
|
||||
{
|
||||
timeCode = new string(timeCode.Where((char c) => !char.IsWhiteSpace(c)).ToArray<char>());
|
||||
string[] array = timeCode.Split(new char[] { ':' });
|
||||
double num;
|
||||
if (array.Length == 0 || array.Length > 4)
|
||||
{
|
||||
num = defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
int num2 = 0;
|
||||
int num3 = 0;
|
||||
double num4 = 0.0;
|
||||
double num5 = 0.0;
|
||||
try
|
||||
{
|
||||
if (Regex.Match(array.Last<string>(), "^\\d+\\.\\d+$").Success)
|
||||
{
|
||||
num4 = double.Parse(array.Last<string>());
|
||||
if (array.Length > 3)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
if (array.Length > 1)
|
||||
{
|
||||
num3 = int.Parse(array[array.Length - 2]);
|
||||
}
|
||||
if (array.Length > 2)
|
||||
{
|
||||
num2 = int.Parse(array[array.Length - 3]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Regex.Match(array.Last<string>(), "^\\d+\\[\\.\\d+\\]$").Success)
|
||||
{
|
||||
string text = new string((from c in array.Last<string>()
|
||||
where c != '[' && c != ']'
|
||||
select c).ToArray<char>());
|
||||
num5 = double.Parse(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Regex.Match(array.Last<string>(), "^\\d*$").Success)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
num5 = (double)int.Parse(array.Last<string>());
|
||||
}
|
||||
if (array.Length > 1)
|
||||
{
|
||||
num4 = (double)int.Parse(array[array.Length - 2]);
|
||||
}
|
||||
if (array.Length > 2)
|
||||
{
|
||||
num3 = int.Parse(array[array.Length - 3]);
|
||||
}
|
||||
if (array.Length > 3)
|
||||
{
|
||||
num2 = int.Parse(array[array.Length - 4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
num = num5 / frameRate + num4 + (double)(num3 * 60) + (double)(num2 * 3600);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
// Token: 0x040000E2 RID: 226
|
||||
public static readonly double kTimeEpsilon = 1E-14;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user