浏览代码

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
/main
Ayhan Sakarya 4 年前
当前提交
65b9d08b
共有 14 个文件被更改,包括 1422 次插入0 次删除
  1. 1001
      UOP1_Project/Assets/Scenes/Settings System.unity
  2. 7
      UOP1_Project/Assets/Scenes/Settings System.unity.meta
  3. 8
      UOP1_Project/Assets/Scripts/Systems.meta
  4. 8
      UOP1_Project/Assets/Scripts/Systems/Settings.meta
  5. 33
      UOP1_Project/Assets/Scripts/Systems/Settings/GraphicsPresets.asset
  6. 8
      UOP1_Project/Assets/Scripts/Systems/Settings/GraphicsPresets.asset.meta
  7. 32
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsPresetsScriptableObject.cs
  8. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsPresetsScriptableObject.cs.meta
  9. 244
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystem.cs
  10. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystem.cs.meta
  11. 48
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsUIController.cs
  12. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsUIController.cs.meta

1001
UOP1_Project/Assets/Scenes/Settings System.unity
文件差异内容过多而无法显示
查看文件

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


fileFormatVersion: 2
guid: c73157bd4ddf4443d97c753bdf357fc1
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Scripts/Systems.meta


fileFormatVersion: 2
guid: 6b9b263f23ed04ec08dddb97eed4830a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Scripts/Systems/Settings.meta


fileFormatVersion: 2
guid: 14c5da797cc504849af118d95f02884e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8d1813776c092430c8317fdd5290dc57, type: 3}
m_Name: GraphicsPresets
m_EditorClassIdentifier:
presetList:
- name: Low
shadowQuality: 0
anisotropicFiltering: 0
antiAliasing: 0
shadowDistance: 20
custom: 0
- name: Middle
shadowQuality: 1
anisotropicFiltering: 1
antiAliasing: 2
shadowDistance: 50
custom: 0
- name: High
shadowQuality: 2
anisotropicFiltering: 2
antiAliasing: 8
shadowDistance: 100
custom: 0

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


fileFormatVersion: 2
guid: 8cdf9b9e9fa3444209be445de7a2a6ac
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

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


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "GraphicsPresets", menuName = "Graphics/Presets", order = 1)]
public class SettingsPresetsScriptableObject : ScriptableObject
{
public List<AdvancedGraphics> presetList;
[Serializable]
public struct AdvancedGraphics
{
public string name;
public ShadowQuality shadowQuality;
public AnisotropicFiltering anisotropicFiltering;
public int antiAliasing;
public float shadowDistance;
public bool custom;
}
public string[] GetPresetNames()
{
string[] presetNames = new string[presetList.Count];
for (int i = 0; i < presetList.Count; i++)
{
presetNames[i] = presetList[i].name;
}
return presetNames;
}
}

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


fileFormatVersion: 2
guid: 8d1813776c092430c8317fdd5290dc57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
public class SettingsSystem : MonoBehaviour
{
[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();
}
public void OnChangeAntialiasing(float value)
{
currentAdvancedGraphics.antiAliasing = (int) value;
currentAdvancedGraphics.custom = true;
UpdateAdvancedGraphicsUI();
}
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();
}
}

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


fileFormatVersion: 2
guid: f22d7dd090554473dafb70b86d96e108
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

48
UOP1_Project/Assets/Scripts/Systems/Settings/SettingsUIController.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SettingsUIController : MonoBehaviour
{
[SerializeField] GameObject generalSettings, graphicsSettings, audioSettings;
[SerializeField] Button generalSettingsButton, graphicsSettingsButton, audioSettingsButton, saveGraphicsSettingsButton, cancelGraphicsSettingsButton;
public enum SettingsType
{
General,
Graphics,
Audio
}
public void OpenGeneralSettings()
{
OpenSetting(SettingsType.General);
}
public void OpenGraphicsSettings()
{
OpenSetting(SettingsType.Graphics);
}
public void OpenAudioSettings()
{
OpenSetting(SettingsType.Audio);
}
public void OnSaveGraphicsSettings()
{
saveGraphicsSettingsButton.interactable = false;
}
void OpenSetting(SettingsType settingType)
{
generalSettings.SetActive(settingType == SettingsType.General);
graphicsSettings.SetActive((settingType == SettingsType.Graphics));
audioSettings.SetActive(settingType == SettingsType.Audio);
generalSettingsButton.interactable = settingType != SettingsType.General;
graphicsSettingsButton.interactable = settingType != SettingsType.Graphics;
audioSettingsButton.interactable = settingType != SettingsType.Audio;
}
}

11
UOP1_Project/Assets/Scripts/Systems/Settings/SettingsUIController.cs.meta


fileFormatVersion: 2
guid: eaa1d1bcaa3ee4cf0af311e19f20e9ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存