forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugPanelFPSCounter.cs
More file actions
51 lines (46 loc) · 1.42 KB
/
DebugPanelFPSCounter.cs
File metadata and controls
51 lines (46 loc) · 1.42 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using UnityEngine;
namespace HoloToolkit.Unity
{
/// <summary>
/// Adds an FPS counter to the debug panel.
/// </summary>
public class DebugPanelFPSCounter : MonoBehaviour
{
/// <summary>
/// Variables for an FPS counter
/// </summary>
private int frameCount;
private int framesPerSecond;
private int lastWholeTime;
private void Start()
{
if (DebugPanel.Instance != null)
{
DebugPanel.Instance.RegisterExternalLogCallback(GetFps);
}
}
private string GetFps()
{
// calculate the fps first
// (Note that we might want to do this in our update loop)
UpdateFps();
return string.Format("FPS: {0}\n", framesPerSecond);
}
/// <summary>
/// Keeps track of rough frames per second.
/// </summary>
private void UpdateFps()
{
frameCount++;
int currentWholeTime = (int) Time.realtimeSinceStartup;
if (currentWholeTime != lastWholeTime)
{
lastWholeTime = currentWholeTime;
framesPerSecond = frameCount;
frameCount = 0;
}
}
}
}