AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
DebugPanelFPSCounter.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity
7 {
11  public class DebugPanelFPSCounter : MonoBehaviour
12  {
16  private int frameCount;
17  private int framesPerSecond;
18  private int lastWholeTime;
19 
20  private void Start()
21  {
22  if (DebugPanel.Instance != null)
23  {
24  DebugPanel.Instance.RegisterExternalLogCallback(GetFps);
25  }
26  }
27 
28  private string GetFps()
29  {
30  // calculate the fps first
31  // (Note that we might want to do this in our update loop)
32  UpdateFps();
33  return string.Format("FPS: {0}\n", framesPerSecond);
34  }
35 
39  private void UpdateFps()
40  {
41  frameCount++;
42  int currentWholeTime = (int) Time.realtimeSinceStartup;
43  if (currentWholeTime != lastWholeTime)
44  {
45  lastWholeTime = currentWholeTime;
46  framesPerSecond = frameCount;
47  frameCount = 0;
48  }
49  }
50  }
51 }
Adds an FPS counter to the debug panel.
Script to control writing the Debug.Log output to a control.
Definition: DebugPanel.cs:12