Mercurial > hg > Game > Games
comparison Orchestland/Assets/LeapMotion/Widgets/Scripts/Utils/FrameRateControls.cs @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 using UnityEngine; | |
2 using System.Collections; | |
3 | |
4 /// <summary> | |
5 /// Provides control of target frame rate. | |
6 /// </summary> | |
7 /// <remarks> | |
8 /// This utility is useful for verifying frame-rate independence of behaviors. | |
9 /// </remarks> | |
10 public class FrameRateControls : MonoBehaviour { | |
11 public int targetRenderRate = 60; // must be > 0 | |
12 public int targetRenderRateStep = 1; | |
13 public int fixedPhysicsRate = 50; // must be > 0 | |
14 public int fixedPhysicsRateStep = 1; | |
15 public KeyCode physicsI = KeyCode.RightShift; | |
16 public KeyCode decrease = KeyCode.DownArrow; | |
17 public KeyCode increase = KeyCode.UpArrow; | |
18 public KeyCode resetAll = KeyCode.Delete; | |
19 | |
20 // Use this for initialization | |
21 void Awake () { | |
22 if (QualitySettings.vSyncCount != 0) { | |
23 Debug.Log("vSync will override target frame rate"); | |
24 return; | |
25 } | |
26 | |
27 Application.targetFrameRate = targetRenderRate; | |
28 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate); | |
29 } | |
30 | |
31 // Update is called once per frame | |
32 void Update () { | |
33 if (Input.GetKey (physicsI)) { | |
34 if (Input.GetKeyDown (decrease)) { | |
35 if (fixedPhysicsRate > fixedPhysicsRateStep) { | |
36 fixedPhysicsRate -= fixedPhysicsRateStep; | |
37 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate); | |
38 } | |
39 } | |
40 if (Input.GetKeyDown (increase)) { | |
41 fixedPhysicsRate += fixedPhysicsRateStep; | |
42 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate); | |
43 } | |
44 } else { | |
45 if (Input.GetKeyDown (decrease)) { | |
46 if (targetRenderRate > targetRenderRateStep) { | |
47 targetRenderRate -= targetRenderRateStep; | |
48 Application.targetFrameRate = targetRenderRate; | |
49 } | |
50 } | |
51 if (Input.GetKeyDown (increase)) { | |
52 targetRenderRate += targetRenderRateStep; | |
53 Application.targetFrameRate = targetRenderRate; | |
54 } | |
55 } | |
56 if (Input.GetKeyDown (resetAll)) { | |
57 Reset(); | |
58 } | |
59 } | |
60 | |
61 public void Reset() { | |
62 targetRenderRate = 60; | |
63 fixedPhysicsRate = 50; | |
64 Application.targetFrameRate = -1; | |
65 Time.fixedDeltaTime = 0.02f; | |
66 } | |
67 } |