-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQualityLevelControl
More file actions
68 lines (56 loc) · 1.76 KB
/
QualityLevelControl
File metadata and controls
68 lines (56 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
This script provides runtime control over the application's quality level with FPS monitoring and UI feedback.
Keyboard button controls:
O - Decrease Level
P - Increase Level
For monitoring, drag and drop UI text objects to the following variables of the script inspector:
- QualityTxt : shows the current quality level = "VeryLow", "Low", "Medium", "High", "VeryHigh", "Ultra"
- FpsTxt : displays frame rate
--------------------------------------------
Author: Ahmed jerbi
Date: September, 2020
www.github.com/Ahmed-jerbi
--------------------------------------------
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class QualityLevelControl : MonoBehaviour
{
public Text QualityTxt;
public Text FpsTxt;
string[] QLevels = { "VeryLow", "Low", "Medium", "High", "VeryHigh", "Ultra" };
int i=5;
float deltaTime;
void Start()
{
// UI init
QualityTxt.text = " Quality level : " + QLevels[i];
}
void Update()
{
//Calculate and Display FPS
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
float fps = 1.0f / deltaTime;
FpsTxt.text = Mathf.Ceil(fps).ToString();
//switch quality level at runtime on button inputs, then update the UI
if (Input.GetKeyDown(KeyCode.O))
{ if (i>0)
{
QualitySettings.DecreaseLevel();
i--;
QualityTxt.text = " Quality level : " + QLevels[i];
}
}
if (Input.GetKeyDown(KeyCode.P))
{
if (i< 5)
{
QualitySettings.IncreaseLevel();
i++;
QualityTxt.text = " Quality level : " + QLevels[i];
}
}
}
}