浏览代码

added volume quality levels

/demo-work
André McGrail 5 年前
当前提交
3148cc39
共有 20 个文件被更改,包括 2220 次插入1104 次删除
  1. 2
      Assets/Data/UniversalRP/PipelineAsset_High.asset
  2. 2
      Assets/Data/UniversalRP/PipelineAsset_Low.asset
  3. 2
      Assets/Data/UniversalRP/PipelineAsset_Medium.asset
  4. 41
      Assets/Resources/AppManager.prefab
  5. 9
      Assets/Resources/VolumeHolder.asset
  6. 39
      Assets/Scripts/Editor/QualitySettingsExtenstion.cs
  7. 23
      Assets/Scripts/GameSystem/AppSettings.cs
  8. 121
      Assets/Scripts/GameSystem/DefaultVolume.cs
  9. 992
      Assets/scenes/MainMenu.unity
  10. 2
      ProjectSettings/QualitySettings.asset
  11. 8
      Assets/Objects/Levels/MainMenu.meta
  12. 8
      Assets/Objects/UI.meta
  13. 48
      Assets/Scripts/GameSystem/VolumeHolder.cs
  14. 11
      Assets/Scripts/GameSystem/VolumeHolder.cs.meta
  15. 1001
      Assets/Objects/Levels/MainMenu/MainMenuLevel.prefab
  16. 7
      Assets/Objects/Levels/MainMenu/MainMenuLevel.prefab.meta
  17. 1001
      Assets/Objects/UI/MainMenuUI.prefab
  18. 7
      Assets/Objects/UI/MainMenuUI.prefab.meta

2
Assets/Data/UniversalRP/PipelineAsset_High.asset


m_UseSRPBatcher: 1
m_SupportsDynamicBatching: 0
m_MixedLightingSupported: 1
m_DebugLevel: 0
m_DebugLevel: 1
m_ColorGradingMode: 0
m_ColorGradingLutSize: 32
m_ShadowType: 1

2
Assets/Data/UniversalRP/PipelineAsset_Low.asset


m_UseSRPBatcher: 1
m_SupportsDynamicBatching: 0
m_MixedLightingSupported: 1
m_DebugLevel: 0
m_DebugLevel: 1
m_ColorGradingMode: 0
m_ColorGradingLutSize: 16
m_ShadowType: 1

2
Assets/Data/UniversalRP/PipelineAsset_Medium.asset


m_UseSRPBatcher: 1
m_SupportsDynamicBatching: 0
m_MixedLightingSupported: 1
m_DebugLevel: 0
m_DebugLevel: 1
m_ColorGradingMode: 0
m_ColorGradingLutSize: 16
m_ShadowType: 1

41
Assets/Resources/AppManager.prefab


m_Component:
- component: {fileID: 3829577903138488073}
- component: {fileID: 3829577903138488074}
- component: {fileID: 3829577903138488075}
- component: {fileID: 3829577903138488068}
- component: {fileID: 7312333174115242941}
m_Layer: 0
m_Name: AppManager

axisBias: 0.5
minScale: 0.5
targetFramerate: 0
qualityVolume: {fileID: 3829577903138488068}
qualityVolumeProfiles:
- {fileID: 11400000, guid: 200e02ce26d6c422db35ba0777d71a09, type: 2}
- {fileID: 11400000, guid: 4fe8789f8ee054ac49d9f7fe042e0918, type: 2}
- {fileID: 11400000, guid: dbf7710ff9a33440f8390ed8e04dbb77, type: 2}
--- !u!114 &3829577903138488075
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3829577903138488069}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 172515602e62fb746b5d573b38a5fe58, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
priority: 0
blendDistance: 0
weight: 1
sharedProfile: {fileID: 11400000, guid: ad80f6934bc444a93bb29c1f6db70cf3, type: 2}
--- !u!114 &3829577903138488068
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3829577903138488069}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 172515602e62fb746b5d573b38a5fe58, type: 3}
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
priority: 1
blendDistance: 0
weight: 1
sharedProfile: {fileID: 11400000, guid: 200e02ce26d6c422db35ba0777d71a09, type: 2}
--- !u!114 &7312333174115242941
MonoBehaviour:
m_ObjectHideFlags: 0

9
Assets/Resources/VolumeHolder.asset


m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 0}
m_Script: {fileID: 11500000, guid: bea894b80a78a4f9a9d5210e78f59e3b, type: 3}
m_EditorClassIdentifier: Assembly-CSharp::DefaultVolumeSwitcher/VolumeHolder
volumes:
m_EditorClassIdentifier: Assembly-CSharp::VolumeHolder
_Volumes:
- {fileID: 11400000, guid: ad80f6934bc444a93bb29c1f6db70cf3, type: 2}
qualityIndicies: 00000000010000000200000003000000
qualityVolumeIndicies: 00000000010000000200000003000000

39
Assets/Scripts/Editor/QualitySettingsExtenstion.cs


EditorGUILayout.BeginVertical(Styles.frameBox);
GUILayout.Label($"Quality Level: {names[displayAssetIndex]}", Styles.header);
EditorGUI.BeginChangeCheck();
if (EditorGUI.EndChangeCheck() && displayAssetIndex != 0)
{
QualitySettings.SetQualityLevel(displayAssetIndex-1);
DefaultVolume.instance.UpdateVolume();
}
if (displayAssetIndex != 0)
{

}
EditorGUILayout.EndHorizontal();
var volHolder = Resources.Load<DefaultVolumeSwitcher.VolumeHolder>("VolumeHolder");
var volHolder = Resources.Load<VolumeHolder>("VolumeHolder");
string[] names = new string[volHolder.volumes.Length];
for (int i = 0; i < names.Length; i++)
string[] names = new string[volHolder._Volumes.Length + 1];
names[0] = "None";
for (int i = 1; i < names.Length; i++)
names[i] = volHolder.volumes[i].name;
names[i] = $"{volHolder._Volumes[i - 1].name} ({typeof(VolumeProfile)})";
if (volHolder.VolumeQualityIndicies.ContainsKey(displayAssetIndex))
if (volHolder.ContainsKey(displayAssetIndex))
volumeIndex[displayAssetIndex] = volHolder.VolumeQualityIndicies[displayAssetIndex];
volumeIndex[displayAssetIndex] = volHolder.GetValue(displayAssetIndex) + 1;
}
EditorGUI.BeginChangeCheck();

if (volHolder.VolumeQualityIndicies.ContainsKey(displayAssetIndex))
if (volHolder.ContainsKey(displayAssetIndex))
volHolder.VolumeQualityIndicies[displayAssetIndex] = volumeIndex[displayAssetIndex];
volHolder.SetKey(displayAssetIndex, volumeIndex[displayAssetIndex] - 1);
volHolder.VolumeQualityIndicies.Add(displayAssetIndex, volumeIndex[displayAssetIndex]);
volHolder.Add(displayAssetIndex, volumeIndex[displayAssetIndex] - 1);
DefaultVolume.instance.UpdateVolume();
Editor volumeSettings = Editor.CreateEditor(volHolder.volumes[volumeIndex[displayAssetIndex]]);
volumeSettings.OnInspectorGUI();
var volIndex = volumeIndex[displayAssetIndex] - 1;
if (volIndex >= 0)
{
Editor volumeSettings = Editor.CreateEditor(volHolder._Volumes[volIndex]);
volumeSettings.OnInspectorGUI();
}
else
{
EditorGUILayout.HelpBox("No Volume Selected for this Quality Level.", MessageType.Info);
}
}
EditorGUILayout.EndVertical();

23
Assets/Scripts/GameSystem/AppSettings.cs


public Framerate targetFramerate = Framerate._30;
private float currentDynamicScale = 1.0f;
private float maxScale = 1.0f;
[Header("Quality Level Settings")]
public Volume qualityVolume;
public VolumeProfile[] qualityVolumeProfiles = new VolumeProfile[3];
private int qualityLevel;
// Use this for initialization
void OnEnable()

void Initialize()
{
Application.targetFrameRate = 300;
qualityLevel = QualitySettings.GetQualityLevel();
qualityVolume.profile = qualityVolumeProfiles[qualityLevel];
}
private void Start()

var renderScale = Mathf.Clamp(res / camera.pixelWidth, 0.1f, 1.0f);
maxScale = renderScale;
#if !UNITY_EDITOR
}
void UpdateQualitySettings(int level)
{
qualityLevel = level;
qualityVolume.profile = qualityVolumeProfiles[level];
#else
Debug.LogWarning(
$"{this} Render Scale {maxScale} not enabled in Editor, using {UniversalRenderPipeline.asset.renderScale}.");
#endif
var level = QualitySettings.GetQualityLevel();
if(level != qualityLevel)
UpdateQualitySettings(level);
if (Camera.main)
{
if (variableResolution)

121
Assets/Scripts/GameSystem/DefaultVolume.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using UnityEngine.Rendering.Universal;
#if UNITY_EDITOR
using UnityEditor;
#endif
public static class DefaultVolume
public class DefaultVolume : MonoBehaviour
public static List<VolumeProfile> DefaultVolumes = new List<VolumeProfile>();
public static void AddVolumes(List<VolumeProfile> volumes)
public static DefaultVolume instance;
private Volume volBaseComponent;
private Volume volQualityComponent;
private VolumeHolder volHolder;
private void OnEnable()
DefaultVolumes.AddRange(volumes);
OnValidate();
}
public class DefaultVolumeSwitcher : MonoBehaviour
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
static void LoadVolumeManager()
private void OnValidate()
if (FindObjectOfType<VolumeManager>() != null)
return;
if (!instance)
instance = this;
gameObject.hideFlags = HideFlags.HideAndDontSave;
if(!volBaseComponent)
volBaseComponent = gameObject.AddComponent<Volume>();
volBaseComponent.priority = -100;
if(!volQualityComponent)
volQualityComponent = gameObject.AddComponent<Volume>();
volQualityComponent.priority = 100;
if(!volHolder)
volHolder = Resources.Load<VolumeHolder>("VolumeHolder");
var go = new GameObject { name = "[Volume Manager]" };
var volMan = go.AddComponent<VolumeManager>();
volMan.Volumes = DefaultVolume.DefaultVolumes;
volMan.vol = go.AddComponent<Volume>();
DontDestroyOnLoad(go);
UpdateVolume();
public class VolumeManager : MonoBehaviour
public void UpdateVolume()
public List<VolumeProfile> Volumes = new List<VolumeProfile>();
public Volume vol;
private void OnEnable()
if (volHolder)
{
//Setup Base Vol if needed
var baseVolIndex = volHolder.GetValue(0);
if (baseVolIndex >= 0)
{
var vol = volHolder._Volumes[baseVolIndex];
volBaseComponent.sharedProfile = vol;
}
else
{
volBaseComponent.sharedProfile = null;
}
//Setup Quality Vol if needed
var qualityVolIndex = volHolder.GetValue(QualitySettings.GetQualityLevel() + 1);
if (qualityVolIndex >= 0)
{
var vol = volHolder._Volumes[qualityVolIndex];
volQualityComponent.sharedProfile = vol;
}
else
{
volQualityComponent.sharedProfile = null;
}
}
if (UniversalRenderPipeline.asset.debugLevel != PipelineDebugLevel.Disabled)
vol.profile = Volumes[QualitySettings.GetQualityLevel()];
string vols = "";
foreach (var vol in VolumeManager.instance.stack.components)
{
vols += $"{vol.Key.Name}\n";
}
Debug.Log($"Updated volumes:\n" +
$" Base Volume : {volBaseComponent.sharedProfile?.name}\n" +
$" Quality Volume : {volQualityComponent.sharedProfile?.name}\n" +
$"Total Volume Stack is now:\n" +
$"{vols}");
[CreateAssetMenu(fileName = "VolumeHolder", menuName = "Volume Holder", order = 0)]
public class VolumeHolder : ScriptableObject
}
#if UNITY_EDITOR
[InitializeOnLoad]
public class StartupVolume
{
private const string goName = "[Volume Manager]";
static StartupVolume()
public VolumeProfile[] volumes;
[SerializeField]
public Dictionary<int, int> VolumeQualityIndicies = new Dictionary<int, int>();
var obj = GameObject.Find(goName)?.GetComponent<DefaultVolume>();
if (obj != null)
{
return;
}
var go = new GameObject { name = goName };
var volMan = go.AddComponent<DefaultVolume>();
obj = volMan;
}
}
#endif

992
Assets/scenes/MainMenu.unity
文件差异内容过多而无法显示
查看文件

2
ProjectSettings/QualitySettings.asset


QualitySettings:
m_ObjectHideFlags: 0
serializedVersion: 5
m_CurrentQuality: 1
m_CurrentQuality: 2
m_QualitySettings:
- serializedVersion: 2
name: Low

8
Assets/Objects/Levels/MainMenu.meta


fileFormatVersion: 2
guid: 594b57c46a9fe4bdfa534a2d37cbe2f6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Objects/UI.meta


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

48
Assets/Scripts/GameSystem/VolumeHolder.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
[CreateAssetMenu(fileName = "VolumeHolder", menuName = "Volume Holder", order = 0)]
public class VolumeHolder : ScriptableObject
{
[SerializeField]
public VolumeProfile[] _Volumes;
[SerializeField]
public List<int> qualityIndicies = new List<int>();
[SerializeField]
public List<int> qualityVolumeIndicies = new List<int>();
public bool ContainsKey(int key)
{
return qualityIndicies.Contains(key);
}
public void Add(int key, int value)
{
qualityIndicies.Add(key);
qualityVolumeIndicies.Add(value);
}
public void SetKey(int key, int value)
{
if (qualityIndicies.Contains(key))
{
qualityVolumeIndicies[qualityIndicies.IndexOf(key)] = value;
}
else
{
Add(key, value);
}
}
public int GetValue(int key)
{
if (qualityIndicies.Contains(key))
{
return qualityVolumeIndicies[qualityIndicies.IndexOf(key)];
}
throw new Exception(message: $"{qualityIndicies} does not contain key {key}");
}
}

11
Assets/Scripts/GameSystem/VolumeHolder.cs.meta


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

1001
Assets/Objects/Levels/MainMenu/MainMenuLevel.prefab
文件差异内容过多而无法显示
查看文件

7
Assets/Objects/Levels/MainMenu/MainMenuLevel.prefab.meta


fileFormatVersion: 2
guid: 705cc40ed7b2348689ba68fd4bc915b3
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/Objects/UI/MainMenuUI.prefab
文件差异内容过多而无法显示
查看文件

7
Assets/Objects/UI/MainMenuUI.prefab.meta


fileFormatVersion: 2
guid: 56de8e58d1a974ab880e61b104d7ef98
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存