浏览代码
Made a refactor of the used setting classes as follows:
Made a refactor of the used setting classes as follows:
- Logic is now split into sub components: Genera, Graphics, Audio and Input (currently empty as input system is wip) - The settings system class can be used to get information from all sub components, a distributor - Fixed an issue with Screen resolution not being correct when in windowed mode (Screen.currentResolution gives back desktop resolution when in windowed mode) - Added Input UI elements which are placeholders for now, once the input system is done this can be populated like the other settings sub components/main
Ayhan Sakarya
4 年前
当前提交
05abd3e9
共有 12 个文件被更改,包括 976 次插入 和 337 次删除
-
668UOP1_Project/Assets/Scenes/Settings System.unity
-
21UOP1_Project/Assets/Scripts/Systems/Settings/SettingsPresetsScriptableObject.cs
-
246UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystem.cs
-
14UOP1_Project/Assets/Scripts/Systems/Settings/SettingsUIController.cs
-
44UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemAudioComponent.cs
-
11UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemAudioComponent.cs.meta
-
44UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGeneralComponent.cs
-
11UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGeneralComponent.cs.meta
-
208UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGraphicsComponent.cs
-
11UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGraphicsComponent.cs.meta
-
24UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemSubComponents.cs
-
11UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemSubComponents.cs.meta
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using TMPro; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.UI; |
|||
using UnityEngine; |
|||
[SerializeField] TMP_Dropdown resolutionsDropdown; |
|||
[SerializeField] TMP_Dropdown languageDropdown; |
|||
[SerializeField] TMP_Dropdown shadowQualityDropdown; |
|||
[SerializeField] TMP_Dropdown anisotropicFilteringDropdown; |
|||
[SerializeField] TMP_Dropdown qualityPresetsDropdown; |
|||
[SerializeField] Slider antiAliasingSlider; |
|||
[SerializeField] Slider shadowDistanceSlider; |
|||
[SerializeField] Slider musicVolumeSlider; |
|||
[SerializeField] Slider sfxVolumeSlider; |
|||
[SerializeField] TextMeshProUGUI antiAliasingText; |
|||
[SerializeField] TextMeshProUGUI shadowDistanceText; |
|||
[SerializeField] SettingsPresetsScriptableObject settingsPresets; |
|||
|
|||
public bool FullScreen { get; private set; } |
|||
public float MusicVolume { get; private set; } |
|||
public float SfxVolume { get; private set; } |
|||
public LanguageSetting Language { get; private set; } |
|||
|
|||
SettingsPresetsScriptableObject.AdvancedGraphics currentAdvancedGraphics, previousAdvancedGraphics; |
|||
int currentQualityLevel, previousQualityLevel; //-1 is custom
|
|||
|
|||
public enum LanguageSetting |
|||
{ |
|||
English, |
|||
German, |
|||
//TODO: which languages are going to be supported?
|
|||
} |
|||
|
|||
void Start() |
|||
{ |
|||
//TODO: Load previous settings data via save/load interface
|
|||
resolutionsDropdown.AddOptions(GetResolutionsDropdownData()); |
|||
languageDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(LanguageSetting)))); |
|||
qualityPresetsDropdown.AddOptions(GetDropdownData(settingsPresets.GetPresetNames(), "Custom")); |
|||
foreach (string s in QualitySettings.names) |
|||
{ |
|||
Debug.Log(s); |
|||
} |
|||
anisotropicFilteringDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(AnisotropicFiltering)))); |
|||
shadowQualityDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(ShadowQuality)))); |
|||
LoadCurrentSettings(); |
|||
} |
|||
|
|||
void LoadCurrentSettings() |
|||
{ |
|||
int resolutionIndex = 0; |
|||
//TODO: load previous resolution setting. If not existing find current resolution index
|
|||
for (int i = 0; i < Screen.resolutions.Length; i++) |
|||
{ |
|||
if (Screen.currentResolution.ToString() == Screen.resolutions[i].ToString()) |
|||
{ |
|||
resolutionIndex = i; |
|||
} |
|||
} |
|||
|
|||
resolutionsDropdown.SetValueWithoutNotify(resolutionIndex); |
|||
//TODO: load quality level from previous session. If custom, set qualityPresetsDropdown to custom. Option "custom" is added in GetQualityPresetsDropdownData()
|
|||
previousQualityLevel = currentQualityLevel; |
|||
currentAdvancedGraphics = settingsPresets.presetList[currentQualityLevel]; //Set to lowest preset initially
|
|||
previousAdvancedGraphics = currentAdvancedGraphics; |
|||
qualityPresetsDropdown.SetValueWithoutNotify(currentAdvancedGraphics.custom ? qualityPresetsDropdown.options.Count-1 : currentQualityLevel); |
|||
|
|||
UpdateAdvancedGraphicsUI(); |
|||
|
|||
//TODO: load previous language setting
|
|||
Language = LanguageSetting.English; |
|||
languageDropdown.SetValueWithoutNotify((int) Language); |
|||
//TODO: load previous fullscreen setting
|
|||
Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen; |
|||
//TODO: load previous music volume setting
|
|||
MusicVolume = 0.5f; |
|||
musicVolumeSlider.SetValueWithoutNotify(MusicVolume); |
|||
//TODO: load previous sfx volume setting
|
|||
SfxVolume = 0.5f; |
|||
sfxVolumeSlider.SetValueWithoutNotify(SfxVolume); |
|||
} |
|||
|
|||
void SelectGraphicsPreset(int level) |
|||
{ |
|||
QualitySettings.SetQualityLevel(0, true); |
|||
UpdateAdvancedGraphicsUI(); |
|||
} |
|||
|
|||
void UpdateAdvancedGraphicsUI() |
|||
{ |
|||
anisotropicFilteringDropdown.SetValueWithoutNotify((int) currentAdvancedGraphics.anisotropicFiltering); |
|||
antiAliasingSlider.SetValueWithoutNotify(currentAdvancedGraphics.antiAliasing); |
|||
shadowDistanceSlider.SetValueWithoutNotify(currentAdvancedGraphics.shadowDistance); |
|||
shadowQualityDropdown.SetValueWithoutNotify((int) currentAdvancedGraphics.shadowQuality); |
|||
shadowDistanceText.text = currentAdvancedGraphics.shadowDistance.ToString(); |
|||
antiAliasingText.text = currentAdvancedGraphics.antiAliasing.ToString(); |
|||
|
|||
qualityPresetsDropdown.SetValueWithoutNotify(currentAdvancedGraphics.custom ? qualityPresetsDropdown.options.Count-1 : currentQualityLevel); |
|||
} |
|||
|
|||
List<TMP_Dropdown.OptionData> GetResolutionsDropdownData() |
|||
{ |
|||
List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>(); |
|||
for (int i = 0; i < Screen.resolutions.Length; i++) |
|||
{ |
|||
options.Add(new TMP_Dropdown.OptionData(Screen.resolutions[i].ToString())); |
|||
} |
|||
|
|||
return options; |
|||
} |
|||
|
|||
List<TMP_Dropdown.OptionData> GetDropdownData(string[] optionNames, params string[] customOptions) |
|||
{ |
|||
List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>(); |
|||
foreach (string option in optionNames) |
|||
{ |
|||
options.Add(new TMP_Dropdown.OptionData(option)); |
|||
} |
|||
|
|||
foreach (string option in customOptions) |
|||
{ |
|||
options.Add(new TMP_Dropdown.OptionData(option)); |
|||
} |
|||
return options; |
|||
} |
|||
|
|||
#region GENERAL SETTINGS
|
|||
|
|||
public void OnChangeLanguage(int languageIndex) |
|||
{ |
|||
Language = (LanguageSetting) languageIndex; |
|||
Debug.Log("Language set to: " + Language); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region GRAPHICS SETTINGS
|
|||
|
|||
public void OnChangeFullscreen(bool fullScreen) |
|||
{ |
|||
Screen.fullScreenMode = fullScreen ? FullScreenMode.ExclusiveFullScreen : FullScreenMode.Windowed; |
|||
} |
|||
|
|||
public void OnChangeResolution(int resolutionIndex) |
|||
{ |
|||
Resolution newResolution = Screen.resolutions[resolutionIndex]; |
|||
Screen.SetResolution(newResolution.width, newResolution.height, Screen.fullScreenMode); |
|||
} |
|||
|
|||
public void OnChangeAnisotropicFiltering(int anisoLevel) |
|||
{ |
|||
currentAdvancedGraphics.anisotropicFiltering = (AnisotropicFiltering) anisoLevel; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateAdvancedGraphicsUI(); |
|||
} |
|||
[SerializeField] SettingsSystemGeneralComponent generalComponent; |
|||
[SerializeField] SettingsSystemGraphicsComponent graphicsComponent; |
|||
[SerializeField] SettingsSystemAudioComponent audioComponent; |
|||
public void OnChangeAntialiasing(float value) |
|||
{ |
|||
currentAdvancedGraphics.antiAliasing = (int) value; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateAdvancedGraphicsUI(); |
|||
} |
|||
public SettingsSystemGeneralComponent.LanguageSetting Language => generalComponent.Language; |
|||
public bool FullScreen => graphicsComponent.FullScreen; |
|||
public float MusicVolume => audioComponent.MusicVolume; |
|||
public float SfxVolume => audioComponent.SfxVolume; |
|||
public void OnChangeShadowDistance(float shadowDistanceValue) |
|||
{ |
|||
//TODO: configure min max value in slider
|
|||
currentAdvancedGraphics.shadowDistance = shadowDistanceValue; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateAdvancedGraphicsUI(); |
|||
} |
|||
|
|||
public void OnChangeShadowQuality(int level) |
|||
{ |
|||
currentAdvancedGraphics.shadowQuality = (ShadowQuality) level; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateAdvancedGraphicsUI(); |
|||
} |
|||
|
|||
public void OnChangeQualityPreset(int level) |
|||
{ |
|||
if (level >= settingsPresets.presetList.Count) |
|||
{ |
|||
//Custom level chosen
|
|||
currentAdvancedGraphics.custom = true; |
|||
} |
|||
else |
|||
{ |
|||
currentAdvancedGraphics = settingsPresets.presetList[level]; |
|||
} |
|||
currentQualityLevel = level; |
|||
UpdateAdvancedGraphicsUI(); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region AUDIO SETTINGS
|
|||
|
|||
//TODO: clamp volume to [0, 1] or [0, 100]? Change Slider min max value in editor depending on use case
|
|||
public void OnChangeMusicVolume(float volume) |
|||
{ |
|||
MusicVolume = Mathf.Clamp(volume, 0.0f, 1.0f); |
|||
} |
|||
|
|||
//TODO: clamp volume to [0, 1] or [0, 100]? Change Slider min max value in editor depending on use case
|
|||
public void OnChangeSfxVolume(float volume) |
|||
{ |
|||
SfxVolume = Mathf.Clamp(volume, 0.0f, 1.0f); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
public void OnSaveGraphicsSettings() |
|||
{ |
|||
QualitySettings.anisotropicFiltering = currentAdvancedGraphics.anisotropicFiltering; |
|||
QualitySettings.antiAliasing = currentAdvancedGraphics.antiAliasing; |
|||
QualitySettings.shadowDistance = currentAdvancedGraphics.shadowDistance; |
|||
QualitySettings.shadows = currentAdvancedGraphics.shadowQuality; |
|||
|
|||
previousAdvancedGraphics = currentAdvancedGraphics; |
|||
previousQualityLevel = currentQualityLevel; |
|||
Debug.Log("Antialiasing: " + QualitySettings.antiAliasing); |
|||
Debug.Log("Anisotropic Filtering: " + QualitySettings.anisotropicFiltering); |
|||
Debug.Log("Shadow Distance: " + QualitySettings.shadowDistance); |
|||
Debug.Log("Shadow Quality: " + QualitySettings.shadows); |
|||
} |
|||
|
|||
public void OnCancelGraphicsSettings() |
|||
{ |
|||
currentAdvancedGraphics = previousAdvancedGraphics; |
|||
currentQualityLevel = previousQualityLevel; |
|||
QualitySettings.anisotropicFiltering = currentAdvancedGraphics.anisotropicFiltering; |
|||
QualitySettings.antiAliasing = currentAdvancedGraphics.antiAliasing; |
|||
QualitySettings.shadowDistance = currentAdvancedGraphics.shadowDistance; |
|||
QualitySettings.shadows = currentAdvancedGraphics.shadowQuality; |
|||
|
|||
UpdateAdvancedGraphicsUI(); |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
|
|||
public class SettingsSystemAudioComponent : SettingsSystemSubComponents |
|||
{ |
|||
[SerializeField] Slider musicVolumeSlider; |
|||
[SerializeField] Slider sfxVolumeSlider; |
|||
|
|||
public float MusicVolume { get; private set; } |
|||
public float SfxVolume { get; private set; } |
|||
|
|||
void Start() |
|||
{ |
|||
Setup(); |
|||
} |
|||
|
|||
protected override void Setup() |
|||
{ |
|||
//TODO: load previous music volume setting
|
|||
MusicVolume = 50f; |
|||
musicVolumeSlider.SetValueWithoutNotify(MusicVolume); |
|||
//TODO: load previous sfx volume setting
|
|||
SfxVolume = 50f; |
|||
sfxVolumeSlider.SetValueWithoutNotify(SfxVolume); |
|||
} |
|||
|
|||
#region UI CALLBACKS
|
|||
|
|||
//TODO: clamp volume to [0, 1] or [0, 100]? Change Slider min max value in editor depending on use case
|
|||
public void OnChangeMusicVolume(float volume) |
|||
{ |
|||
MusicVolume = Mathf.Clamp(volume, 0.0f, 100.0f); |
|||
} |
|||
|
|||
//TODO: clamp volume to [0, 1] or [0, 100]? Change Slider min max value in editor depending on use case
|
|||
public void OnChangeSfxVolume(float volume) |
|||
{ |
|||
SfxVolume = Mathf.Clamp(volume, 0.0f, 100.0f); |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b4ddec376a8a84d5791648f98ca38df6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
public class SettingsSystemGeneralComponent : SettingsSystemSubComponents |
|||
{ |
|||
[SerializeField] TMP_Dropdown languageDropdown; |
|||
|
|||
SettingsSystem settingsSystem; |
|||
public LanguageSetting Language { get; private set; } |
|||
|
|||
public enum LanguageSetting |
|||
{ |
|||
English, |
|||
German, |
|||
//TODO: which languages are going to be supported?
|
|||
} |
|||
|
|||
void Start() |
|||
{ |
|||
Setup(); |
|||
} |
|||
|
|||
protected override void Setup() |
|||
{ |
|||
settingsSystem = transform.parent.GetComponent<SettingsSystem>(); |
|||
languageDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(LanguageSetting)))); |
|||
//TODO: Load previous serialized session data via Load/Save class
|
|||
Language = SettingsSystemGeneralComponent.LanguageSetting.English; |
|||
languageDropdown.SetValueWithoutNotify((int) Language); |
|||
} |
|||
|
|||
#region UI CALLBACKS
|
|||
|
|||
public void OnChangeLanguage(int languageIndex) |
|||
{ |
|||
Language = (LanguageSetting) languageIndex; |
|||
Debug.Log("Language set to: " + Language); |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5cbf3de30afb74cb39db3ba32a890fda |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using TMPro; |
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
|
|||
public class SettingsSystemGraphicsComponent : SettingsSystemSubComponents |
|||
{ |
|||
[SerializeField] TMP_Dropdown resolutionsDropdown; |
|||
[SerializeField] TMP_Dropdown shadowQualityDropdown; |
|||
[SerializeField] TMP_Dropdown anisotropicFilteringDropdown; |
|||
[SerializeField] TMP_Dropdown graphicsPresetsDropdown; |
|||
[SerializeField] Slider antiAliasingSlider; |
|||
[SerializeField] Slider shadowDistanceSlider; |
|||
[SerializeField] Toggle fullscreenToggle; |
|||
[SerializeField] TextMeshProUGUI antiAliasingText; |
|||
[SerializeField] TextMeshProUGUI shadowDistanceText; |
|||
[SerializeField] SettingsPresetsScriptableObject settingsPresets; |
|||
|
|||
bool setupComplete; |
|||
|
|||
//Advanced graphic settings
|
|||
SettingsPresetsScriptableObject.AdvancedGraphics currentAdvancedGraphics, previousAdvancedGraphics; |
|||
int currentQualityIndex, previousQualityIndex; |
|||
|
|||
//Fullscreen settings
|
|||
public bool FullScreen { get; private set; } |
|||
bool previouslyInFullScreen; |
|||
|
|||
//Resolution setting
|
|||
Resolution currentResolution, previousResolution; |
|||
|
|||
void OnEnable() |
|||
{ |
|||
if (!setupComplete) |
|||
{ |
|||
Setup(); |
|||
} |
|||
} |
|||
|
|||
protected override void Setup() |
|||
{ |
|||
resolutionsDropdown.AddOptions(GetResolutionsDropdownData()); |
|||
graphicsPresetsDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(SettingsPresetsScriptableObject.GraphicsQualityLevel)), "Custom")); |
|||
anisotropicFilteringDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(AnisotropicFiltering)))); |
|||
shadowQualityDropdown.AddOptions(GetDropdownData(Enum.GetNames(typeof(ShadowQuality)))); |
|||
|
|||
//RESOLUTION
|
|||
//TODO: apparently, unity keeps the resolution which was set in the last session. But there is no method to get this resolution in the next session
|
|||
//TODO: because Screen.currentResolution in windowed mode gives back the resolution of the desktop, not the unity window resolution
|
|||
currentResolution = Screen.resolutions[Screen.resolutions.Length - 1]; //Initially set highest possible resolution on device
|
|||
previousResolution = currentResolution; |
|||
Screen.SetResolution(currentResolution.width, currentResolution.height, Screen.fullScreenMode, currentResolution.refreshRate); |
|||
SelectCurrentResolution(); |
|||
|
|||
//FULLSCREEN MODE
|
|||
//TODO: load previous session fullscreen setting
|
|||
FullScreen = Screen.fullScreenMode == FullScreenMode.ExclusiveFullScreen; |
|||
previouslyInFullScreen = FullScreen; |
|||
fullscreenToggle.SetIsOnWithoutNotify(FullScreen); |
|||
|
|||
//QUALITY PRESET
|
|||
//TODO: instead of hardcoding the level here, load data from previous session
|
|||
currentQualityIndex = (int) SettingsPresetsScriptableObject.GraphicsQualityLevel.Low; |
|||
previousQualityIndex = currentQualityIndex; |
|||
currentAdvancedGraphics = settingsPresets.presetList[currentQualityIndex]; //Set to lowest preset initially
|
|||
previousAdvancedGraphics = currentAdvancedGraphics; |
|||
graphicsPresetsDropdown.SetValueWithoutNotify(currentAdvancedGraphics.custom ? graphicsPresetsDropdown.options.Count-1 : currentQualityIndex); |
|||
UpdateUI(); |
|||
setupComplete = true; |
|||
} |
|||
|
|||
List<TMP_Dropdown.OptionData> GetResolutionsDropdownData() |
|||
{ |
|||
List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>(); |
|||
for (int i = 0; i < Screen.resolutions.Length; i++) |
|||
{ |
|||
options.Add(new TMP_Dropdown.OptionData(Screen.resolutions[i].ToString())); |
|||
} |
|||
|
|||
return options; |
|||
} |
|||
|
|||
void UpdateUI() |
|||
{ |
|||
anisotropicFilteringDropdown.SetValueWithoutNotify((int) currentAdvancedGraphics.anisotropicFiltering); |
|||
antiAliasingSlider.SetValueWithoutNotify(currentAdvancedGraphics.antiAliasing); |
|||
shadowDistanceSlider.SetValueWithoutNotify(currentAdvancedGraphics.shadowDistance); |
|||
shadowQualityDropdown.SetValueWithoutNotify((int) currentAdvancedGraphics.shadowQuality); |
|||
shadowDistanceText.text = currentAdvancedGraphics.shadowDistance.ToString(); |
|||
antiAliasingText.text = currentAdvancedGraphics.antiAliasing.ToString(); |
|||
fullscreenToggle.SetIsOnWithoutNotify(FullScreen); |
|||
graphicsPresetsDropdown.SetValueWithoutNotify(currentAdvancedGraphics.custom ? graphicsPresetsDropdown.options.Count-1 : currentQualityIndex); |
|||
} |
|||
|
|||
#region UI CALLBACKS
|
|||
|
|||
public void OnChangeFullscreen(bool fullScreen) |
|||
{ |
|||
Screen.fullScreenMode = fullScreen ? FullScreenMode.ExclusiveFullScreen : FullScreenMode.Windowed; |
|||
FullScreen = fullScreen; |
|||
} |
|||
|
|||
public void OnChangeResolution(int resolutionIndex) |
|||
{ |
|||
Debug.Log("Index: " + resolutionIndex); |
|||
currentResolution = Screen.resolutions[resolutionIndex]; |
|||
Screen.SetResolution(currentResolution.width, currentResolution.height, Screen.fullScreenMode, currentResolution.refreshRate); |
|||
} |
|||
|
|||
public void OnChangeAnisotropicFiltering(int anisoLevel) |
|||
{ |
|||
currentAdvancedGraphics.anisotropicFiltering = (AnisotropicFiltering) anisoLevel; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateUI(); |
|||
} |
|||
|
|||
public void OnChangeAntialiasing(float value) |
|||
{ |
|||
currentAdvancedGraphics.antiAliasing = (int) value; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateUI(); |
|||
} |
|||
|
|||
public void OnChangeShadowDistance(float shadowDistanceValue) |
|||
{ |
|||
//TODO: configure min max value in slider
|
|||
currentAdvancedGraphics.shadowDistance = shadowDistanceValue; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateUI(); |
|||
} |
|||
|
|||
public void OnChangeShadowQuality(int level) |
|||
{ |
|||
currentAdvancedGraphics.shadowQuality = (ShadowQuality) level; |
|||
currentAdvancedGraphics.custom = true; |
|||
UpdateUI(); |
|||
} |
|||
|
|||
public void OnChangeQualityPreset(int level) |
|||
{ |
|||
if (level >= settingsPresets.presetList.Count) |
|||
{ |
|||
//Custom level chosen
|
|||
currentAdvancedGraphics.custom = true; |
|||
} |
|||
else |
|||
{ |
|||
currentAdvancedGraphics = settingsPresets.presetList[level]; |
|||
} |
|||
currentQualityIndex = level; |
|||
UpdateUI(); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
void SelectCurrentResolution() |
|||
{ |
|||
int resolutionIndex = 0; |
|||
//TODO: is resolution persistent once it is set? Need to test in build
|
|||
for (int i = 0; i < Screen.resolutions.Length; i++) |
|||
{ |
|||
if (currentResolution.width == Screen.resolutions[i].width && |
|||
currentResolution.height == Screen.resolutions[i].height && |
|||
currentResolution.refreshRate == Screen.resolutions[i].refreshRate) |
|||
{ |
|||
resolutionIndex = i; |
|||
} |
|||
} |
|||
|
|||
resolutionsDropdown.SetValueWithoutNotify(resolutionIndex); |
|||
} |
|||
|
|||
public void OnSaveGraphicsSettings() |
|||
{ |
|||
QualitySettings.anisotropicFiltering = currentAdvancedGraphics.anisotropicFiltering; |
|||
QualitySettings.antiAliasing = currentAdvancedGraphics.antiAliasing; |
|||
QualitySettings.shadowDistance = currentAdvancedGraphics.shadowDistance; |
|||
QualitySettings.shadows = currentAdvancedGraphics.shadowQuality; |
|||
|
|||
previousAdvancedGraphics = currentAdvancedGraphics; |
|||
previousQualityIndex = currentQualityIndex; |
|||
previousResolution = currentResolution; |
|||
previouslyInFullScreen = FullScreen; |
|||
Debug.Log("Saving resolution state: " + currentResolution); |
|||
Debug.Log(("Saving fullscreen mode state: " + previouslyInFullScreen)); |
|||
} |
|||
|
|||
public void OnCancelGraphicsSettings() |
|||
{ |
|||
currentAdvancedGraphics = previousAdvancedGraphics; |
|||
currentQualityIndex = previousQualityIndex; |
|||
QualitySettings.anisotropicFiltering = currentAdvancedGraphics.anisotropicFiltering; |
|||
QualitySettings.antiAliasing = currentAdvancedGraphics.antiAliasing; |
|||
QualitySettings.shadowDistance = currentAdvancedGraphics.shadowDistance; |
|||
QualitySettings.shadows = currentAdvancedGraphics.shadowQuality; |
|||
Screen.SetResolution(previousResolution.width, previousResolution.height, previouslyInFullScreen ? FullScreenMode.ExclusiveFullScreen : FullScreenMode.Windowed, previousResolution.refreshRate); |
|||
// It might be a good idea to wait for the end of frame here with a coroutine, because setResolution actually is executed at the end of the next frame
|
|||
//TODO: Observe this for issues in future
|
|||
currentResolution = previousResolution; |
|||
FullScreen = previouslyInFullScreen; |
|||
SelectCurrentResolution(); |
|||
UpdateUI(); |
|||
Debug.Log("New Resolution: " + previousResolution); |
|||
Debug.Log("New fullscreen mode: " + FullScreen); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bb22202e544f74ee4b52c6ab7035e5e2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using TMPro; |
|||
using UnityEngine; |
|||
|
|||
public abstract class SettingsSystemSubComponents : MonoBehaviour |
|||
{ |
|||
protected List<TMP_Dropdown.OptionData> GetDropdownData(string[] optionNames, params string[] customOptions) |
|||
{ |
|||
List<TMP_Dropdown.OptionData> options = new List<TMP_Dropdown.OptionData>(); |
|||
foreach (string option in optionNames) |
|||
{ |
|||
options.Add(new TMP_Dropdown.OptionData(option)); |
|||
} |
|||
|
|||
foreach (string option in customOptions) |
|||
{ |
|||
options.Add(new TMP_Dropdown.OptionData(option)); |
|||
} |
|||
return options; |
|||
} |
|||
|
|||
protected abstract void Setup(); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e7303151e63a7428a8ecef4430d922fc |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue