Skip to content

Commit d7f9e07

Browse files
committed
feat: Add more quality util
1 parent 5dce07c commit d7f9e07

File tree

5 files changed

+113
-17
lines changed

5 files changed

+113
-17
lines changed

Assets/JCSUnity/Movies/Underwater.mp4.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/JCSUnity/Scripts/UI/Dropdown/JCS_DropdownQuality.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void Refresh()
7878

7979
// Default to the current quality level.
8080
{
81-
string text = QualityName();
81+
string text = JCS_Quality.ItName();
8282

8383
JCS_UIUtil.Dropdown_SetSelection(this, text);
8484
}
@@ -106,21 +106,7 @@ private void OnValueChanged_TMP(TMP_Dropdown dropdown)
106106
}
107107
private void OnValueChanged(string text)
108108
{
109-
int level = QualitySettings.names.IndexOfItem(text);
110-
111-
QualitySettings.SetQualityLevel(level);
112-
}
113-
114-
/// <summary>
115-
/// Return the name of the current quality level.
116-
/// </summary>
117-
private string QualityName()
118-
{
119-
int level = QualitySettings.GetQualityLevel();
120-
121-
string text = QualitySettings.names[level];
122-
123-
return text;
109+
JCS_Quality.SetLevel(text);
124110
}
125111
}
126112
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* $File: JCS_Quality.cs $
3+
* $Date: 2025-07-14 01:14:38 $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright (c) 2025 by Shen, Jen-Chieh $
8+
*/
9+
using UnityEngine;
10+
using MyBox;
11+
12+
namespace JCSUnity
13+
{
14+
/// <summary>
15+
/// Quality settings utilities.
16+
/// </summary>
17+
public static class JCS_Quality
18+
{
19+
/* Variables */
20+
21+
/* Setter & Getter */
22+
23+
/* Functions */
24+
25+
/// <summary>
26+
/// Return the name of the current quality level.
27+
/// </summary>
28+
public static string ItName()
29+
{
30+
int level = QualitySettings.GetQualityLevel();
31+
32+
string text = QualitySettings.names[level];
33+
34+
return text;
35+
}
36+
public static int ItLevel()
37+
{
38+
return QualitySettings.GetQualityLevel();
39+
}
40+
41+
/// <summary>
42+
/// Return current quality settings by name.
43+
/// </summary>
44+
public static int ByName(string name)
45+
{
46+
return QualitySettings.names.IndexOfItem(name);
47+
}
48+
49+
/// <summary>
50+
/// Set the quality level by name.
51+
/// </summary>
52+
public static void SetLevel(string name)
53+
{
54+
int level = ByName(name);
55+
56+
SetLevel(level);
57+
}
58+
// @compatible
59+
public static void SetLevel(int level)
60+
{
61+
QualitySettings.SetQualityLevel(level);
62+
}
63+
64+
/// <summary>
65+
/// Return true if the quality level reaches.
66+
/// </summary>
67+
public static bool IsAbove(string name)
68+
{
69+
return ByName(name) <= ItLevel();
70+
}
71+
72+
/// <summary>
73+
/// Return true if the quality level not reaches.
74+
/// </summary>
75+
public static bool IsBelow(string name)
76+
{
77+
return ItLevel() < ByName(name);
78+
}
79+
80+
/// <summary>
81+
/// Return true if the quality level is the exact level.
82+
/// </summary>
83+
public static bool Is(params string[] names)
84+
{
85+
foreach (string name in names)
86+
{
87+
if (ByName(name) == ItLevel())
88+
return true;
89+
}
90+
91+
return false;
92+
}
93+
}
94+
}

Assets/JCSUnity/Scripts/Util/JCS_Quality.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# JCS_Quality
2+
3+
Quality settings utilities.
4+
5+
## Functions
6+
7+
| Name | Description |
8+
|:---------|:-----------------------------------------------------|
9+
| ItName | Return the name of the current quality level. |
10+
| ByName | Return current quality settings by name. |
11+
| SetLevel | Set the quality level by name. |
12+
| IsAbove | Return true if the quality level reaches. |
13+
| IsBelow | Return true if the quality level not reaches. |
14+
| Is | Return true if the quality level is the exact level. |

0 commit comments

Comments
 (0)