-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathSentryBehavior.cs
68 lines (57 loc) · 1.87 KB
/
SentryBehavior.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
using System;
using System.Collections;
using System.Threading;
using UnityEngine;
namespace Sentry.Unity
{
public class SentryBehavior : MonoBehaviour
{
private int goodFrames;
private int slowFrames;
private int frozFrames;
private float slowThreshold = 0.02f;
private float frozThreshold = 1.0f;
private float lastTime;
private void Start()
{
frozThreshold = Time.maximumDeltaTime;
}
private void Update()
{
MeasureDeltaTime();
CheckFrame();
if (Input.GetKeyDown(KeyCode.S))
{
var sleepDuration = Time.maximumDeltaTime + 0.1f;
Debug.Log($"<color=red>=========== Sleep for: {sleepDuration}ms ===========</color>");
Thread.Sleep((int)(sleepDuration * 1000));
}
}
private void MeasureDeltaTime()
{
var measuredDeltaTime = Time.realtimeSinceStartup - lastTime;
lastTime = Time.realtimeSinceStartup;
Debug.Log($"Measured delta time: {measuredDeltaTime}");
}
private void CheckFrame()
{
if (Time.deltaTime >= frozThreshold)
{
frozFrames++;
}
else if (Time.deltaTime > slowThreshold)
{
slowFrames++;
}
else
{
goodFrames++;
}
Debug.Log($"Good: {goodFrames} | Slow: {slowFrames} | Frozen: {frozFrames}");
}
// TODO: Flush events. See note on OnApplicationQuit
//private void OnApplicationPause() =>
// TODO: Flush events, see note on OnApplicationQuit
// private void OnApplicationFocus { if (!focusStatus) Flush events! }
}
}