-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityTime.cs
More file actions
87 lines (77 loc) · 2.59 KB
/
Copy pathUnityTime.cs
File metadata and controls
87 lines (77 loc) · 2.59 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
namespace UnityIceFebruary
{
using IceFebruary;
using IceFebruary.Collections;
using IceFebruary.Time;
using UnityEngine;
/// <summary>
/// Untiy realization of the core time management interface.
/// Controls execution of regular and fixed update frames.
/// </summary>
public sealed class UnityTime : BaseEntity, ITime
{
private readonly EntityFastArray<IFrame> _frameArray;
private readonly EntityFastArray<IFixedFrame> _fixedFrameArray;
/// <summary>
/// Creates a new untiy realization of the core time management interface.
/// Controls execution of regular and fixed update frames.
/// </summary>
public UnityTime(int startArraySize)
{
_frameArray = new(startArraySize);
_fixedFrameArray = new(startArraySize);
}
/// <summary>
/// Total elapsed game time in seconds since system startup.
/// </summary>
public float CurrentTime => Time.time;
/// <summary>
/// Fixed time step duration specifically for fixed updates.
/// </summary>
public float FixedFrameRate
{
get => Time.fixedDeltaTime;
set => Time.fixedDeltaTime = value;
}
/// <summary>
/// Registers and launches a frame update listener.
/// </summary>
public void LaunchIFrame(IFrame frame)
{
if (frame.Exists())
_frameArray.Register(frame);
}
/// <summary>
/// Registers and launches a fixed frame update listener.
/// </summary>
public void LaunchIFixedFrame(IFixedFrame fixedFrame)
{
if (fixedFrame.Exists())
_fixedFrameArray.Register(fixedFrame);
}
/// <summary>
/// Processes a single regular frame iteration.
/// </summary>
public void DoFrame(float frameLength)
{
for (int index = 0; index < _frameArray.Length; index++)
{
IFrame frame = _frameArray.Entities[index];
if (frame.Exists())
frame.OnFrame(frameLength);
}
}
/// <summary>
/// Processes a single fixed frame tick step.
/// </summary>
public void DoFixedFrame()
{
for (int index = 0; index < _fixedFrameArray.Length; index++)
{
IFixedFrame fixedFrame = _fixedFrameArray.Entities[index];
if (fixedFrame.Exists())
fixedFrame.OnFixedFrame();
}
}
}
}