-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
82 lines (68 loc) · 2.36 KB
/
Game.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
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
using UnityEngine;
using Binocle.Processors;
namespace Binocle
{
public class Game : MonoBehaviour
{
public static float TimeRate = 1f;
private const float CLAMP_ADD = 0.008333334f;
private const float FRAME_RATE = 60f;
private const float FULL_DELTA = 0.01666667f;
public int DesignWidth
{
get { return _designWidth; }
set { _designWidth = value; }
}
private int _designWidth = 320;
public int DesignHeight
{
get { return _designHeight; }
set { _designHeight = value; }
}
private int _designHeight = 240;
public static float LastTimeMult {get; private set;}
public static float TimeMult {get; private set;}
public static float DeltaTime {get; private set;}
public static float ActualDeltaTime {get; private set;}
public bool IsFixedTimeStep = false;
protected PixelCamera pixelCamera;
public virtual void Start()
{
pixelCamera = Camera.main.gameObject.AddComponent<PixelCamera>();
pixelCamera.DesignWidth = _designWidth;
pixelCamera.DesignHeight = _designHeight;
var guiCamera = GameObject.Find("GUI Camera");
if (guiCamera != null)
{
PixelCamera pixelCameraGUI = guiCamera.AddComponent<PixelCamera>();
pixelCameraGUI.DesignWidth = _designWidth;
pixelCameraGUI.DesignHeight = _designHeight;
}
ComponentTypeManager.Initialize();
}
public virtual void Update()
{
LastTimeMult = TimeMult;
ActualDeltaTime = Time.deltaTime * TimeRate;
if (IsFixedTimeStep)
{
TimeMult = 1f * TimeRate;
DeltaTime = 0.01666667f * TimeRate;
}
else
{
DeltaTime = Mathf.Min(ActualDeltaTime, 0.01666667f * (TimeRate + 0.008333334f));
TimeMult = DeltaTime / 0.01666667f;
}
}
public T CreateScene<T>(string name) where T : Scene
{
GameObject go = new GameObject(name);
var s = go.AddComponent<T>();
object o = (object)s;
Scene scene = (Scene)o;
scene.Game = this;
return s;
}
}
}