Skip to content

Commit 83885b0

Browse files
committed
Implementation of current Settings System includes the following:
- Implemented General tab - Language setting - Implemented Graphics tab - Graphics Presets, Resolution (all supported resolutions on users device), fullscreen mode settings - Implemented Advanced Graphics - Anisotropic filtering, Anti-Aliasing, Shadow Distance, Shadow Quality settings - Implemented Audio tab - Music Volume, Sfx Volume settings - Moved SettingsSystem scripts to Scripts/Systems/Settings (if we use asmdef files in the future this hiararchy might be better than throwin every script under the scripts folder) - Added scriptable object which holds graphics presets - Updated SettingsSystem script to utilize the presets object
1 parent 21bd0e2 commit 83885b0

12 files changed

+11873
-0
lines changed

UOP1_Project/Assets/Scenes/Settings System.unity

Lines changed: 11452 additions & 0 deletions
Large diffs are not rendered by default.

UOP1_Project/Assets/Scenes/Settings System.unity.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UOP1_Project/Assets/Scripts/Systems.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UOP1_Project/Assets/Scripts/Systems/Settings.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 8d1813776c092430c8317fdd5290dc57, type: 3}
13+
m_Name: GraphicsPresets
14+
m_EditorClassIdentifier:
15+
presetList:
16+
- name: Low
17+
shadowQuality: 0
18+
anisotropicFiltering: 0
19+
antiAliasing: 0
20+
shadowDistance: 20
21+
custom: 0
22+
- name: Middle
23+
shadowQuality: 1
24+
anisotropicFiltering: 1
25+
antiAliasing: 2
26+
shadowDistance: 50
27+
custom: 0
28+
- name: High
29+
shadowQuality: 2
30+
anisotropicFiltering: 2
31+
antiAliasing: 8
32+
shadowDistance: 100
33+
custom: 0

UOP1_Project/Assets/Scripts/Systems/Settings/GraphicsPresets.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
[CreateAssetMenu(fileName = "GraphicsPresets", menuName = "Graphics/Presets", order = 1)]
7+
public class SettingsPresetsScriptableObject : ScriptableObject
8+
{
9+
public List<AdvancedGraphics> presetList;
10+
11+
[Serializable]
12+
public struct AdvancedGraphics
13+
{
14+
public string name;
15+
public ShadowQuality shadowQuality;
16+
public AnisotropicFiltering anisotropicFiltering;
17+
public int antiAliasing;
18+
public float shadowDistance;
19+
public bool custom;
20+
}
21+
22+
public string[] GetPresetNames()
23+
{
24+
string[] presetNames = new string[presetList.Count];
25+
for (int i = 0; i < presetList.Count; i++)
26+
{
27+
presetNames[i] = presetList[i].name;
28+
}
29+
30+
return presetNames;
31+
}
32+
}

UOP1_Project/Assets/Scripts/Systems/Settings/SettingsPresetsScriptableObject.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using TMPro;
6+
using UnityEngine;
7+
using UnityEngine.Rendering;
8+
using UnityEngine.UI;
9+
10+
public class SettingsSystem : MonoBehaviour
11+
{
12+
[SerializeField] TMP_Dropdown resolutionsDropdown;
13+
[SerializeField] TMP_Dropdown languageDropdown;
14+
[SerializeField] TMP_Dropdown shadowQualityDropdown;
15+
[SerializeField] TMP_Dropdown anisotropicFilteringDropdown;
16+
[SerializeField] TMP_Dropdown qualityPresetsDropdown;
17+
[SerializeField] Slider antiAliasingSlider;
18+
[SerializeField] Slider shadowDistanceSlider;
19+
[SerializeField] Slider musicVolumeSlider;
20+
[SerializeField] Slider sfxVolumeSlider;
21+
[SerializeField] TextMeshProUGUI antiAliasingText;
22+
[SerializeField] TextMeshProUGUI shadowDistanceText;
23+
[SerializeField] SettingsPresetsScriptableObject settingsPresets;
24+
25+
public bool FullScreen { get; private set; }
26+
public float MusicVolume { get; private set; }
27+
public float SfxVolume { get; private set; }
28+
public LanguageSetting Language { get; private set; }
29+
30+
SettingsPresetsScriptableObject.AdvancedGraphics currentAdvancedGraphics, previousAdvancedGraphics;
31+
int currentQualityLevel, previousQualityLevel; //-1 is custom
32+
33+
public enum LanguageSetting
34+
{
35+
English,
36+
German,
37+
//TODO: which languages are going to be supported?
38+
}
39+
40+
void Start()
41+
{
42+
//TODO: Load previous settings data via save/load interface
43+
resolutionsDropdown.AddOptions(GetResolutionsDropdownData());
44+
languageDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(LanguageSetting))));
45+
qualityPresetsDropdown.AddOptions(GetDropdownData(settingsPresets.GetPresetNames(), "Custom"));
46+
foreach (string s in QualitySettings.names)
47+
{
48+
Debug.Log(s);
49+
}
50+
anisotropicFilteringDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(AnisotropicFiltering))));
51+
shadowQualityDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(ShadowQuality))));
52+
LoadCurrentSettings();
53+
}
54+
55+
void LoadCurrentSettings()
56+
{
57+
int resolutionIndex = 0;
58+
//TODO: load previous resolution setting. If not existing find current resolution index
59+
for (int i = 0; i < Screen.resolutions.Length; i++)
60+
{
61+
if (Screen.currentResolution.ToString() == Screen.resolutions[i].ToString())
62+
{
63+
resolutionIndex = i;
64+
}
65+
}
66+
67+
resolutionsDropdown.SetValueWithoutNotify(resolutionIndex);
68+
//TODO: load quality level from previous session. If custom, set qualityPresetsDropdown to custom. Option "custom" is added in GetQualityPresetsDropdownData()
69+
previousQualityLevel = currentQualityLevel;
70+
currentAdvancedGraphics = settingsPresets.presetList[currentQualityLevel]; //Set to lowest preset initially
71+
previousAdvancedGraphics = currentAdvancedGraphics;
72+
qualityPresetsDropdown.SetValueWithoutNotify(currentAdvancedGraphics.custom ? qualityPresetsDropdown.options.Count-1 : currentQualityLevel);
73+
74+
UpdateAdvancedGraphicsUI();
75+
76+
//TODO: load previous language setting
77+
Language = LanguageSetting.English;
78+
languageDropdown.SetValueWithoutNotify((int) Language);
79+
//TODO: load previous fullscreen setting
80+
Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
81+
//TODO: load previous music volume setting
82+
MusicVolume = 0.5f;
83+
musicVolumeSlider.SetValueWithoutNotify(MusicVolume);
84+
//TODO: load previous sfx volume setting
85+
SfxVolume = 0.5f;
86+
sfxVolumeSlider.SetValueWithoutNotify(SfxVolume);
87+
}
88+
89+
void SelectGraphicsPreset(int level)
90+
{
91+
QualitySettings.SetQualityLevel(0, true);
92+
UpdateAdvancedGraphicsUI();
93+
}
94+
95+
void UpdateAdvancedGraphicsUI()
96+
{
97+
anisotropicFilteringDropdown.SetValueWithoutNotify((int) currentAdvancedGraphics.anisotropicFiltering);
98+
antiAliasingSlider.SetValueWithoutNotify(currentAdvancedGraphics.antiAliasing);
99+
shadowDistanceSlider.SetValueWithoutNotify(currentAdvancedGraphics.shadowDistance);
100+
shadowQualityDropdown.SetValueWithoutNotify((int) currentAdvancedGraphics.shadowQuality);
101+
shadowDistanceText.text = currentAdvancedGraphics.shadowDistance.ToString();
102+
antiAliasingText.text = currentAdvancedGraphics.antiAliasing.ToString();
103+
104+
qualityPresetsDropdown.SetValueWithoutNotify(currentAdvancedGraphics.custom ? qualityPresetsDropdown.options.Count-1 : currentQualityLevel);
105+
}
106+
107+
List<TMP_Dropdown.OptionData> GetResolutionsDropdownData()
108+
{
109+
List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
110+
for (int i = 0; i < Screen.resolutions.Length; i++)
111+
{
112+
options.Add(new TMP_Dropdown.OptionData(Screen.resolutions[i].ToString()));
113+
}
114+
115+
return options;
116+
}
117+
118+
List<TMP_Dropdown.OptionData> GetDropdownData(string[] optionNames, params string[] customOptions)
119+
{
120+
List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>();
121+
foreach (string option in optionNames)
122+
{
123+
options.Add(new TMP_Dropdown.OptionData(option));
124+
}
125+
126+
foreach (string option in customOptions)
127+
{
128+
options.Add(new TMP_Dropdown.OptionData(option));
129+
}
130+
return options;
131+
}
132+
133+
#region GENERAL SETTINGS
134+
135+
public void OnChangeLanguage(int languageIndex)
136+
{
137+
Language = (LanguageSetting) languageIndex;
138+
Debug.Log("Language set to: " + Language);
139+
}
140+
141+
#endregion
142+
143+
#region GRAPHICS SETTINGS
144+
145+
public void OnChangeFullscreen(bool fullScreen)
146+
{
147+
Screen.fullScreenMode = fullScreen ? FullScreenMode.ExclusiveFullScreen : FullScreenMode.Windowed;
148+
}
149+
150+
public void OnChangeResolution(int resolutionIndex)
151+
{
152+
Resolution newResolution = Screen.resolutions[resolutionIndex];
153+
Screen.SetResolution(newResolution.width, newResolution.height, Screen.fullScreenMode);
154+
}
155+
156+
public void OnChangeAnisotropicFiltering(int anisoLevel)
157+
{
158+
currentAdvancedGraphics.anisotropicFiltering = (AnisotropicFiltering) anisoLevel;
159+
currentAdvancedGraphics.custom = true;
160+
UpdateAdvancedGraphicsUI();
161+
}
162+
163+
public void OnChangeAntialiasing(float value)
164+
{
165+
currentAdvancedGraphics.antiAliasing = (int) value;
166+
currentAdvancedGraphics.custom = true;
167+
UpdateAdvancedGraphicsUI();
168+
}
169+
170+
public void OnChangeShadowDistance(float shadowDistanceValue)
171+
{
172+
//TODO: configure min max value in slider
173+
currentAdvancedGraphics.shadowDistance = shadowDistanceValue;
174+
currentAdvancedGraphics.custom = true;
175+
UpdateAdvancedGraphicsUI();
176+
}
177+
178+
public void OnChangeShadowQuality(int level)
179+
{
180+
currentAdvancedGraphics.shadowQuality = (ShadowQuality) level;
181+
currentAdvancedGraphics.custom = true;
182+
UpdateAdvancedGraphicsUI();
183+
}
184+
185+
public void OnChangeQualityPreset(int level)
186+
{
187+
if (level >= settingsPresets.presetList.Count)
188+
{
189+
//Custom level chosen
190+
currentAdvancedGraphics.custom = true;
191+
}
192+
else
193+
{
194+
currentAdvancedGraphics = settingsPresets.presetList[level];
195+
}
196+
currentQualityLevel = level;
197+
UpdateAdvancedGraphicsUI();
198+
}
199+
200+
#endregion
201+
202+
#region AUDIO SETTINGS
203+
204+
//TODO: clamp volume to [0, 1] or [0, 100]? Change Slider min max value in editor depending on use case
205+
public void OnChangeMusicVolume(float volume)
206+
{
207+
MusicVolume = Mathf.Clamp(volume, 0.0f, 1.0f);
208+
}
209+
210+
//TODO: clamp volume to [0, 1] or [0, 100]? Change Slider min max value in editor depending on use case
211+
public void OnChangeSfxVolume(float volume)
212+
{
213+
SfxVolume = Mathf.Clamp(volume, 0.0f, 1.0f);
214+
}
215+
216+
#endregion
217+
218+
public void OnSaveGraphicsSettings()
219+
{
220+
QualitySettings.anisotropicFiltering = currentAdvancedGraphics.anisotropicFiltering;
221+
QualitySettings.antiAliasing = currentAdvancedGraphics.antiAliasing;
222+
QualitySettings.shadowDistance = currentAdvancedGraphics.shadowDistance;
223+
QualitySettings.shadows = currentAdvancedGraphics.shadowQuality;
224+
225+
previousAdvancedGraphics = currentAdvancedGraphics;
226+
previousQualityLevel = currentQualityLevel;
227+
Debug.Log("Antialiasing: " + QualitySettings.antiAliasing);
228+
Debug.Log("Anisotropic Filtering: " + QualitySettings.anisotropicFiltering);
229+
Debug.Log("Shadow Distance: " + QualitySettings.shadowDistance);
230+
Debug.Log("Shadow Quality: " + QualitySettings.shadows);
231+
}
232+
233+
public void OnCancelGraphicsSettings()
234+
{
235+
currentAdvancedGraphics = previousAdvancedGraphics;
236+
currentQualityLevel = previousQualityLevel;
237+
QualitySettings.anisotropicFiltering = currentAdvancedGraphics.anisotropicFiltering;
238+
QualitySettings.antiAliasing = currentAdvancedGraphics.antiAliasing;
239+
QualitySettings.shadowDistance = currentAdvancedGraphics.shadowDistance;
240+
QualitySettings.shadows = currentAdvancedGraphics.shadowQuality;
241+
242+
UpdateAdvancedGraphicsUI();
243+
}
244+
}

UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystem.cs.meta

Lines changed: 11 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)