Skip to content

Commit 8202d95

Browse files
committed
feat: Add quality settings dropdown
1 parent f2ccee5 commit 8202d95

File tree

10 files changed

+3709
-993
lines changed

10 files changed

+3709
-993
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* $File: JCS_DropdownQuality.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 © 2025 by Shen, Jen-Chieh $
8+
*/
9+
using UnityEngine;
10+
using UnityEngine.UI;
11+
using TMPro;
12+
using MyBox;
13+
14+
namespace JCSUnity
15+
{
16+
/// <summary>
17+
/// A dropdown menu let you choose the quality level.
18+
/// </summary>
19+
public class JCS_DropdownQuality : JCS_DropdownObject
20+
{
21+
/* Variables */
22+
23+
[Separator("Initialize Variables (JCS_DropdownQuality)")]
24+
25+
[Tooltip("If true, remove all other options at the beginning.")]
26+
[SerializeField]
27+
private bool mRemoveAllOptions = true;
28+
29+
[Separator("Runtime Variables (JCS_DropdownQuality)")]
30+
31+
[Tooltip("Should expensive changes be applied.")]
32+
[SerializeField]
33+
private bool mApplyExpensiveChanges = false;
34+
35+
/* Setter & Getter */
36+
37+
public bool RemoveAllOptions { get { return mRemoveAllOptions; } set { this.mRemoveAllOptions = value; } }
38+
public bool ApplyExpensiveChanges { get { return mApplyExpensiveChanges; } set { this.mApplyExpensiveChanges = value; } }
39+
40+
/* Functions */
41+
42+
private void Start()
43+
{
44+
Refresh();
45+
46+
AddListener();
47+
}
48+
49+
private void AddListener()
50+
{
51+
mDropdownLegacy?.onValueChanged.AddListener(delegate
52+
{
53+
OnValueChanged_Legacy(mDropdownLegacy);
54+
});
55+
56+
mDropdownTMP?.onValueChanged.AddListener(delegate
57+
{
58+
OnValueChanged_TMP(mDropdownTMP);
59+
});
60+
61+
// Run once.
62+
OnValueChanged_Legacy(mDropdownLegacy);
63+
OnValueChanged_TMP(mDropdownTMP);
64+
}
65+
66+
/// <summary>
67+
/// Refresh all options once.
68+
/// </summary>
69+
public void Refresh()
70+
{
71+
if (mRemoveAllOptions)
72+
ClearOptions();
73+
74+
foreach (string option in QualitySettings.names)
75+
{
76+
JCS_UIUtil.Dropdown_AddOption(this, option);
77+
}
78+
79+
// Default to the current quality level.
80+
{
81+
int level = QualitySettings.GetQualityLevel();
82+
83+
string text = QualitySettings.names[level];
84+
85+
JCS_UIUtil.Dropdown_SetSelection(this, text);
86+
}
87+
88+
JCS_UIUtil.Dropdown_RefreshSelection(this);
89+
}
90+
91+
private void OnValueChanged_Legacy(Dropdown dropdown)
92+
{
93+
if (dropdown == null)
94+
return;
95+
96+
string text = JCS_UIUtil.Dropdown_GetSelectedValue(dropdown);
97+
98+
OnValueChanged(text);
99+
}
100+
private void OnValueChanged_TMP(TMP_Dropdown dropdown)
101+
{
102+
if (dropdown == null)
103+
return;
104+
105+
string text = JCS_UIUtil.Dropdown_GetSelectedValue(dropdown);
106+
107+
OnValueChanged(text);
108+
}
109+
private void OnValueChanged(string text)
110+
{
111+
int level = QualitySettings.names.IndexOfItem(text);
112+
113+
QualitySettings.SetQualityLevel(level);
114+
}
115+
}
116+
}

Assets/JCSUnity/Scripts/UI/Dropdown/JCS_DropdownQuality.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.

0 commit comments

Comments
 (0)