HKI Core
TimeSystem.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using HKI.Core.Variables;
3 
4 namespace HKI.Core.GameSystems
5 {
9  [System.Serializable]
10  public class TimeSystem
11  {
12  // Public variables
13  [SerializeField] Integer GameSpeed = null;
14 
15  [SerializeField] float[] GameSpeedFactors = new float[] { 0.0f, 1.0f, 4.0f, 10.0f };
16 
17  [SerializeField] Float DeltaTime = null;
18  [SerializeField] Float FixedDeltaTime = null;
19  [SerializeField] Float UnscaledDeltaTime = null;
20  [SerializeField] Float UnscaledFixedDeltaTime = null;
21 
22  // Interface functions
23  public void Setup()
24  {
25  GameSpeed.OnValueChanged += UpdateTimeScale;
26  UpdateTimeScale();
27  }
28 
29  public void Update()
30  {
31  if(DeltaTime != null)
32  DeltaTime.SetValue = Time.deltaTime;
33 
34  if(UnscaledDeltaTime != null)
35  UnscaledDeltaTime.SetValue = Time.unscaledDeltaTime;
36  }
37 
38  public void FixedUpdate()
39  {
40  if (FixedDeltaTime != null)
41  FixedDeltaTime.SetValue = Time.fixedTime;
42 
43  if (UnscaledFixedDeltaTime != null)
44  UnscaledFixedDeltaTime.SetValue = Time.fixedUnscaledDeltaTime;
45  }
46 
47  public void Shutdown()
48  {
49  GameSpeed.OnValueChanged -= UpdateTimeScale;
50  Time.timeScale = 1.0f;
51  }
52 
53  // Helper function
55  {
56  Time.timeScale = GameSpeedFactors[GameSpeed.Value];
57  }
58  }
59 }
This system stores all engine time values so that can be used by other systems without having to call...
Definition: TimeSystem.cs:10
Implementation of a float value as a HKIVar via HKIVarGeneric.
Definition: Float.cs:16
Implementation of a integer value as a HKIVar via HKIVarGeneric.
Definition: Integer.cs:16