/
TimeProviderUTC.cs
45 lines (41 loc) · 1.33 KB
/
TimeProviderUTC.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace uStableObject
{
[CreateAssetMenu(menuName = "uStableObject/TimeProvider/UTC")]
public class TimeProviderUTC : TimeProvider
{
DateTime _epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
uint _lastUpdateFrame;
float _lastUpdateValuef;
uint _lastUpdateValue;
public override uint CurrentTime
{
get
{
this.UpdateTime();
return (this._lastUpdateValue);
}
}
public override float CurrentTimeF
{
get
{
this.UpdateTime();
return (this._lastUpdateValuef);
}
}
void UpdateTime()
{
if (this._lastUpdateFrame != Time.frameCount)
{
this._lastUpdateFrame = (uint)Time.frameCount;
double totalSec = (DateTime.UtcNow - this._epochStart).TotalSeconds;
this._lastUpdateValue = (uint)totalSec;
this._lastUpdateValuef = (float)(totalSec - this._lastUpdateValue);
}
}
}
}