using System; using UnityEngine; namespace Leap.Unity { public class FrameRateControls : MonoBehaviour { private void Awake() { if (QualitySettings.vSyncCount != 0) { Debug.LogWarning("vSync will override target frame rate. vSyncCount = " + QualitySettings.vSyncCount); } Application.targetFrameRate = this.targetRenderRate; Time.fixedDeltaTime = 1f / (float)this.fixedPhysicsRate; } private void Update() { if (Input.GetKey(this.unlockRender)) { if (Input.GetKeyDown(this.decrease) && this.targetRenderRate > this.targetRenderRateStep) { this.targetRenderRate -= this.targetRenderRateStep; Application.targetFrameRate = this.targetRenderRate; } if (Input.GetKeyDown(this.increase)) { this.targetRenderRate += this.targetRenderRateStep; Application.targetFrameRate = this.targetRenderRate; } if (Input.GetKeyDown(this.resetRate)) { this.ResetRender(); } } if (Input.GetKey(this.unlockPhysics)) { if (Input.GetKeyDown(this.decrease) && this.fixedPhysicsRate > this.fixedPhysicsRateStep) { this.fixedPhysicsRate -= this.fixedPhysicsRateStep; Time.fixedDeltaTime = 1f / (float)this.fixedPhysicsRate; } if (Input.GetKeyDown(this.increase)) { this.fixedPhysicsRate += this.fixedPhysicsRateStep; Time.fixedDeltaTime = 1f / (float)this.fixedPhysicsRate; } if (Input.GetKeyDown(this.resetRate)) { this.ResetPhysics(); } } } public void ResetRender() { this.targetRenderRate = 60; Application.targetFrameRate = -1; } public void ResetPhysics() { this.fixedPhysicsRate = 50; Time.fixedDeltaTime = 0.02f; } public void ResetAll() { this.ResetRender(); this.ResetPhysics(); } public int targetRenderRate = 60; public int targetRenderRateStep = 1; public int fixedPhysicsRate = 50; public int fixedPhysicsRateStep = 1; public KeyCode unlockRender = KeyCode.RightShift; public KeyCode unlockPhysics = KeyCode.LeftShift; public KeyCode decrease = KeyCode.DownArrow; public KeyCode increase = KeyCode.UpArrow; public KeyCode resetRate = KeyCode.Backspace; } }