浏览代码

Merge branch 'pr/67' into main

/main
uChema 3 年前
当前提交
7cd7c86b
共有 22 个文件被更改,包括 1573 次插入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. 8
      UOP1_Project/Assets/Scripts/Systems/Settings/GraphicsPresets.asset.meta
  6. 41
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsPresetsScriptableObject.cs
  7. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsPresetsScriptableObject.cs.meta
  8. 14
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystem.cs
  9. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystem.cs.meta
  10. 56
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsUIController.cs
  11. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsUIController.cs.meta
  12. 44
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemAudioComponent.cs
  13. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemAudioComponent.cs.meta
  14. 44
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGeneralComponent.cs
  15. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGeneralComponent.cs.meta
  16. 208
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGraphicsComponent.cs
  17. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGraphicsComponent.cs.meta
  18. 24
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemSubComponents.cs
  19. 11
      UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemSubComponents.cs.meta
  20. 33
      UOP1_Project/Assets/Scripts/Systems/Settings/GraphicsPresets.asset

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:

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


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

41
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 GraphicsQualityLevel qualityLevel;
public ShadowQuality shadowQuality;
public AnisotropicFiltering anisotropicFiltering;
public int antiAliasing;
public float shadowDistance;
public bool custom;
}
public enum GraphicsQualityLevel
{
Low,
Middle,
High
}
public AdvancedGraphics GetPresetByQualityLevel(GraphicsQualityLevel level)
{
foreach (AdvancedGraphics preset in presetList)
{
if (level == preset.qualityLevel)
{
return preset;
}
}
return default;
}
}

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:

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


using UnityEngine;
public class SettingsSystem : MonoBehaviour
{
[SerializeField] SettingsSystemGeneralComponent generalComponent;
[SerializeField] SettingsSystemGraphicsComponent graphicsComponent;
[SerializeField] SettingsSystemAudioComponent audioComponent;
public SettingsSystemGeneralComponent.LanguageSetting Language => generalComponent.Language;
public bool FullScreen => graphicsComponent.FullScreen;
public float MusicVolume => audioComponent.MusicVolume;
public float SfxVolume => audioComponent.SfxVolume;
}

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:

56
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, inputSettings;
[SerializeField] Button generalSettingsButton, graphicsSettingsButton, audioSettingsButton, inputSettingsButton, saveGraphicsSettingsButton, cancelGraphicsSettingsButton;
public enum SettingsType
{
General,
Graphics,
Audio,
Input
}
public void OpenGeneralSettings()
{
OpenSetting(SettingsType.General);
}
public void OpenGraphicsSettings()
{
OpenSetting(SettingsType.Graphics);
}
public void OpenAudioSettings()
{
OpenSetting(SettingsType.Audio);
}
public void OpenInputSettings()
{
OpenSetting(SettingsType.Input);
}
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);
inputSettings.SetActive(settingType == SettingsType.Input);
generalSettingsButton.interactable = settingType != SettingsType.General;
graphicsSettingsButton.interactable = settingType != SettingsType.Graphics;
audioSettingsButton.interactable = settingType != SettingsType.Audio;
inputSettingsButton.interactable = settingType != SettingsType.Input;
}
}

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:

44
UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemAudioComponent.cs


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
}

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


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

44
UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGeneralComponent.cs


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
}

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


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

208
UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemGraphicsComponent.cs


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);
}
}

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


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

24
UOP1_Project/Assets/Scripts/Systems/Settings/SettingsSystemSubComponents.cs


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();
}

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


fileFormatVersion: 2
guid: e7303151e63a7428a8ecef4430d922fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
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:
- qualityLevel: 0
shadowQuality: 0
anisotropicFiltering: 0
antiAliasing: 0
shadowDistance: 20
custom: 0
- qualityLevel: 1
shadowQuality: 1
anisotropicFiltering: 1
antiAliasing: 2
shadowDistance: 50
custom: 0
- qualityLevel: 2
shadowQuality: 2
anisotropicFiltering: 2
antiAliasing: 8
shadowDistance: 100
custom: 0
正在加载...
取消
保存