|
|
|
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System;using System.Collections; |
|
|
|
using UnityEngine.SceneManagement; |
|
|
|
using Object = UnityEngine.Object; |
|
|
|
using UnityEngine.ResourceManagement.AsyncOperations; |
|
|
|
using UnityEditor.Build; |
|
|
|
using UnityEditor.Build.Reporting; |
|
|
|
using UnityEditor.AddressableAssets; |
|
|
|
public static DefaultVolume Instance; |
|
|
|
public static DefaultVolume Instance { get; private set; } |
|
|
|
|
|
|
|
private void Start() |
|
|
|
private void Awake() |
|
|
|
if (!Instance) |
|
|
|
{ |
|
|
|
Instance = this; |
|
|
|
if (Application.isPlaying) |
|
|
|
DontDestroyOnLoad(gameObject); |
|
|
|
} |
|
|
|
else if (Instance != this) |
|
|
|
Init(); |
|
|
|
} |
|
|
|
|
|
|
|
public void Init() |
|
|
|
{ |
|
|
|
gameObject.hideFlags = HideFlags.HideAndDontSave; |
|
|
|
|
|
|
|
if (Instance != null && Instance != this) |
|
|
|
Utility.SafeDestroy(this); |
|
|
|
Utility.SafeDestroy(gameObject); |
|
|
|
|
|
|
|
Utility.QualityLevelChange += UpdateVolume; |
|
|
|
UpdateVolume(0, Utility.GetTrueQualityLevel()); // First time set
|
|
|
|
else |
|
|
|
{ |
|
|
|
Instance = this; |
|
|
|
gameObject.name = "[DefaultVolume]"; |
|
|
|
Debug.Log($"Default Volume is {gameObject.GetInstanceID()}"); |
|
|
|
Utility.QualityLevelChange += UpdateVolume; |
|
|
|
UpdateVolume(0, Utility.GetTrueQualityLevel()); // First time set
|
|
|
|
} |
|
|
|
Utility.QualityLevelChange -= UpdateVolume; |
|
|
|
if (Instance == this) |
|
|
|
Instance = null; |
|
|
|
Utility.QualityLevelChange -= UpdateVolume; |
|
|
|
} |
|
|
|
|
|
|
|
private void UpdateVolume(int level, int realLevel) |
|
|
|
|
|
|
|
|
|
|
private IEnumerator LoadAndApplyQualityVolume(int index) |
|
|
|
{ |
|
|
|
var volLoading = qualityVolumes[index].LoadAssetAsync<VolumeProfile>(); |
|
|
|
yield return volLoading; |
|
|
|
volQualityComponent.sharedProfile = volLoading.Result; |
|
|
|
var vol = qualityVolumes[index]; |
|
|
|
if (!vol.OperationHandle.IsValid() || vol.OperationHandle.Status != AsyncOperationStatus.Succeeded) |
|
|
|
{ |
|
|
|
qualityVolumes[index].LoadAssetAsync<VolumeProfile>(); |
|
|
|
} |
|
|
|
yield return vol.OperationHandle; |
|
|
|
volQualityComponent.sharedProfile = vol.OperationHandle.Result as VolumeProfile; |
|
|
|
|
|
|
|
if (UniversalRenderPipeline.asset.debugLevel == PipelineDebugLevel.Disabled) yield break; |
|
|
|
if (volBaseComponent.sharedProfile && volQualityComponent.sharedProfile) |
|
|
|
|
|
|
"Total Volume Stack is now:\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
[InitializeOnLoadMethod] |
|
|
|
#else
|
|
|
|
[RuntimeInitializeOnLoadMethod] |
|
|
|
#endif
|
|
|
|
static void LoadMe() |
|
|
|
{ |
|
|
|
Debug.Log("runtime loading"); |
|
|
|
var vols = Resources.FindObjectsOfTypeAll(typeof(DefaultVolume)) as DefaultVolume[]; |
|
|
|
if (vols == null) return; |
|
|
|
|
|
|
|
if (vols.Length == 0 && Instance == null) |
|
|
|
{ |
|
|
|
var goHandle = Addressables.InstantiateAsync("volume_manager"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
foreach (var vol in vols) |
|
|
|
{ |
|
|
|
if(vol.gameObject.activeSelf && vol.gameObject.activeInHierarchy) |
|
|
|
vol.Init(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
internal class InjectDefaultVolume : IProcessSceneWithReport |
|
|
|
internal class DefaultVolumeEditor : IProcessSceneWithReport |
|
|
|
static InjectDefaultVolume() |
|
|
|
static DefaultVolumeEditor() |
|
|
|
//EditorApplication.delayCall += InjectDefaultVolume;
|
|
|
|
//EditorApplication.playModeStateChanged += StateChange;
|
|
|
|
} |
|
|
|
|
|
|
|
private static void InjectDefaultVolume() |
|
|
|
{ |
|
|
|
if (DefaultVolume.Instance != null) return; |
|
|
|
|
|
|
|
CreateVolumeManager(HideFlags.HideAndDontSave); |
|
|
|
//EditorApplication.delayCall += () => { CreateVolumeManager(HideFlags.HideAndDontSave); };
|
|
|
|
EditorApplication.playModeStateChanged += StateChange; |
|
|
|
|
|
|
|
CreateVolumeManager(HideFlags.DontSaveInEditor); |
|
|
|
} |
|
|
|
|
|
|
|
private static void StateChange(PlayModeStateChange obj) |
|
|
|
|
|
|
case PlayModeStateChange.EnteredEditMode: |
|
|
|
if(DefaultVolume.Instance == null) |
|
|
|
CreateVolumeManager(HideFlags.HideAndDontSave); |
|
|
|
CreateVolumeManager(HideFlags.DontSaveInEditor); |
|
|
|
break; |
|
|
|
case PlayModeStateChange.ExitingEditMode: |
|
|
|
Utility.SafeDestroy(DefaultVolume.Instance); |
|
|
|
|
|
|
|
|
|
|
private static void CreateVolumeManager(HideFlags flags = HideFlags.None) |
|
|
|
{ |
|
|
|
//Addressables
|
|
|
|
//var asset = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(entry.guid);
|
|
|
|
|
|
|
|
|
|
|
|
var obj = |
|
|
|
AssetDatabase.LoadAssetAtPath("Assets/objects/misc/DefaultVolume.prefab", typeof(GameObject)) as |
|
|
|
GameObject; |
|
|
|
|
|
|
_vol.hideFlags = flags; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
*/ |