annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 ´╗┐using UnityEngine;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 using System.Collections;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 /// <summary>
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 /// Provides control of target frame rate.
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 /// </summary>
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 /// <remarks>
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 /// This utility is useful for verifying frame-rate independence of behaviors.
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 /// </remarks>
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 public class FrameRateControls : MonoBehaviour {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 public int targetRenderRate = 60; // must be > 0
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 public int targetRenderRateStep = 1;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 public int fixedPhysicsRate = 50; // must be > 0
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 public int fixedPhysicsRateStep = 1;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 public KeyCode physicsI = KeyCode.RightShift;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 public KeyCode decrease = KeyCode.DownArrow;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 public KeyCode increase = KeyCode.UpArrow;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 public KeyCode resetAll = KeyCode.Delete;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 // Use this for initialization
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 void Awake () {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 if (QualitySettings.vSyncCount != 0) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 Debug.Log("vSync will override target frame rate");
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 return;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 Application.targetFrameRate = targetRenderRate;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate);
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 // Update is called once per frame
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 void Update () {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 if (Input.GetKey (physicsI)) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 if (Input.GetKeyDown (decrease)) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 if (fixedPhysicsRate > fixedPhysicsRateStep) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 fixedPhysicsRate -= fixedPhysicsRateStep;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate);
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 if (Input.GetKeyDown (increase)) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 fixedPhysicsRate += fixedPhysicsRateStep;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 Time.fixedDeltaTime = 1f/((float)fixedPhysicsRate);
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 } else {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 if (Input.GetKeyDown (decrease)) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 if (targetRenderRate > targetRenderRateStep) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 targetRenderRate -= targetRenderRateStep;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 Application.targetFrameRate = targetRenderRate;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 if (Input.GetKeyDown (increase)) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 targetRenderRate += targetRenderRateStep;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 Application.targetFrameRate = targetRenderRate;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 if (Input.GetKeyDown (resetAll)) {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 Reset();
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 public void Reset() {
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 targetRenderRate = 60;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 fixedPhysicsRate = 50;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 Application.targetFrameRate = -1;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 Time.fixedDeltaTime = 0.02f;
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }
f7675884f2a1 Add Orchestland project
Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 }