Tanoda
FrameRateControls.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;
10using System.Collections;
11
12namespace Leap.Unity{
19 public class FrameRateControls : MonoBehaviour {
20 public int targetRenderRate = 60; // must be > 0
21 public int targetRenderRateStep = 1;
22 public int fixedPhysicsRate = 50; // must be > 0
23 public int fixedPhysicsRateStep = 1;
24 public KeyCode unlockRender = KeyCode.RightShift;
25 public KeyCode unlockPhysics = KeyCode.LeftShift;
26 public KeyCode decrease = KeyCode.DownArrow;
27 public KeyCode increase = KeyCode.UpArrow;
28 public KeyCode resetRate = KeyCode.Backspace;
29
30 // Use this for initialization
31 void Awake () {
32 if (QualitySettings.vSyncCount != 0) {
33 Debug.LogWarning ("vSync will override target frame rate. vSyncCount = " + QualitySettings.vSyncCount);
34 }
35
36 Application.targetFrameRate = targetRenderRate;
37 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate);
38 }
39
40 // Update is called once per frame
41 void Update () {
42 if (Input.GetKey (unlockRender)) {
43 if (Input.GetKeyDown (decrease)) {
46 Application.targetFrameRate = targetRenderRate;
47 }
48 }
49 if (Input.GetKeyDown (increase)) {
51 Application.targetFrameRate = targetRenderRate;
52 }
53 if (Input.GetKeyDown (resetRate)) {
55 }
56 }
57 if (Input.GetKey (unlockPhysics)) {
58 if (Input.GetKeyDown (decrease)) {
61 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate);
62 }
63 }
64 if (Input.GetKeyDown (increase)) {
66 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate);
67 }
68 if (Input.GetKeyDown (resetRate)) {
70 }
71 }
72 }
73
74 public void ResetRender() {
76 Application.targetFrameRate = -1;
77 }
78
79 public void ResetPhysics() {
81 Time.fixedDeltaTime = 0.02f;
82 }
83
84 public void ResetAll() {
85 ResetRender ();
86 ResetPhysics ();
87 }
88 }
89}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
Provides control of target frame rate.