Tanoda
FpsLabel.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10
11namespace Leap.Unity {
12 public class FpsLabel : MonoBehaviour {
13
14 [SerializeField]
15 private LeapProvider _provider;
16
17 [SerializeField]
18 private TextMesh _frameRateText;
19
20 private SmoothedFloat _smoothedRenderFps = new SmoothedFloat();
21
22 private void OnEnable() {
23 if (_provider == null) {
24 _provider = Hands.Provider;
25 }
26
27 if (_frameRateText == null) {
28 _frameRateText = GetComponentInChildren<TextMesh>();
29 if (_frameRateText == null) {
30 Debug.LogError("Could not enable FpsLabel because no TextMesh was specified!");
31 enabled = false;
32 }
33 }
34
35 _smoothedRenderFps.delay = 0.3f;
36 _smoothedRenderFps.reset = true;
37 }
38
39 private void Update() {
40 _frameRateText.text = "";
41
42 if (_provider != null) {
43 Frame frame = _provider.CurrentFrame;
44
45 if (frame != null) {
46 _frameRateText.text += "Data FPS:" + _provider.CurrentFrame.CurrentFramesPerSecond.ToString("f2");
47 _frameRateText.text += System.Environment.NewLine;
48 }
49 }
50
51 if (Time.smoothDeltaTime > Mathf.Epsilon) {
52 _smoothedRenderFps.Update(1.0f / Time.smoothDeltaTime, Time.deltaTime);
53 }
54
55 _frameRateText.text += "Render FPS:" + Mathf.RoundToInt(_smoothedRenderFps.value).ToString("f2");
56 }
57 }
58}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
The Frame class represents a set of hand and finger tracking data detected in a single frame.
Definition: Frame.cs:24
float CurrentFramesPerSecond
The instantaneous framerate.
Definition: Frame.cs:148
Provides Frame object data to the Unity application by firing events as soon as Frame data is availab...
Definition: LeapProvider.cs:21
abstract Frame CurrentFrame
The current frame for this update cycle, in world space.
Definition: LeapProvider.cs:37
Time-step independent exponential smoothing.
float Update(float input, float deltaTime=1f)