浏览代码

Potential camera and volume fixes

/seans-add-link-xml
André McGrail 4 年前
当前提交
d9ee8ed7
共有 5 个文件被更改,包括 116 次插入91 次删除
  1. 74
      Assets/Scripts/GameSystem/AppSettings.cs
  2. 109
      Assets/Scripts/GameSystem/DefaultVolume.cs
  3. 10
      Assets/Scripts/Utility/Utility.cs
  4. 6
      Packages/manifest.json
  5. 8
      Assets/scenes/_levels/level_Island/Terrain.meta

74
Assets/Scripts/GameSystem/AppSettings.cs


private static void LevelWasLoaded(Scene scene, LoadSceneMode mode)
{
if (!MainCamera)
{
MainCamera = Camera.main;
}
else
CleanupCameras();
Instance.Invoke(nameof(CleanupLoadingScreen), 0.5f);
}
private static void CleanupCameras()
{
foreach (var c in GameObject.FindGameObjectsWithTag("MainCamera"))
var cams = GameObject.FindGameObjectsWithTag("MainCamera");
foreach (var c in cams)
if (MainCamera != null && c != MainCamera.gameObject)
if (c != MainCamera.gameObject) Destroy(c);
Destroy(c);
}
else
{
MainCamera = c.GetComponent<Camera>();
Instance.Invoke(nameof(CleanupLoadingScreen), 0.5f);
if (Instance.loadingScreenObject != null)
{
Instance.loadingScreen.ReleaseInstance(Instance.loadingScreenObject);
}
if(loadingScreenObject) loadingScreen?.ReleaseInstance(loadingScreenObject);
float res;
switch (maxRenderSize)
var res = maxRenderSize switch
case RenderRes._720p:
res = 1280f;
break;
case RenderRes._1080p:
res = 1920f;
break;
case RenderRes._1440p:
res = 2560f;
break;
default:
res = Screen.width;
break;
}
RenderRes._720p => 1280f,
RenderRes._1080p => 1920f,
RenderRes._1440p => 2560f,
_ => Screen.width
};
if(UniversalRenderPipeline.asset.debugLevel == PipelineDebugLevel.Profiling)
Debug.Log($"Settings render scale to {renderScale * 100}% based on {maxRenderSize.ToString()}");

#if !UNITY_EDITOR
Utility.CheckQualityLevel(); //TODO - hoping to remove one day when we have a quality level callback
#endif
if (!MainCamera) return;
if (variableResolution)

var offset = 0f;
var currentFrametime = Time.deltaTime;
var rate = 0.1f;
const float rate = 0.1f;
switch (targetFramerate)
offset = targetFramerate switch
case Framerate._30:
offset = currentFrametime > (1000f / 30f) ? -rate : rate;
break;
case Framerate._60:
offset = currentFrametime > (1000f / 60f) ? -rate : rate;
break;
case Framerate._120:
offset = currentFrametime > (1000f / 120f) ? -rate : rate;
break;
}
Framerate._30 => currentFrametime > (1000f / 30f) ? -rate : rate,
Framerate._60 => currentFrametime > (1000f / 60f) ? -rate : rate,
Framerate._120 => currentFrametime > (1000f / 120f) ? -rate : rate,
_ => offset
};
currentDynamicScale = Mathf.Clamp(currentDynamicScale + offset, minScale, 1f);

{
return $"level_{Levels[level]}";
}
public static readonly List<string> QualityLevels = new List<string>(){"Low", "Medium", "High"};
public static readonly string[] AiNames =

109
Assets/Scripts/GameSystem/DefaultVolume.cs


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
*/

10
Assets/Scripts/Utility/Utility.cs


{
public static event Action<int, int> QualityLevelChange;
private static int lastQualityLevel = -1;
if(UniversalRenderPipeline.asset.debugLevel != PipelineDebugLevel.Disabled)
Debug.Log($"Quality level changed:{lastQualityLevel} to {curLevel}");
var realIndex = GetTrueQualityLevel(curLevel);

{
return Regex.Replace(input, @"\s+", "");
}
Object.DestroyImmediate(obj);
EditorApplication.delayCall += () => Object.DestroyImmediate(obj);
return;
#else
Object.Destroy(obj);

}
}
#if UNITY_EDITOR
[InitializeOnLoad]
internal class UtilityScheduler

6
Packages/manifest.json


"com.unity.2d.sprite": "1.0.0",
"com.unity.addressables": "1.14.2",
"com.unity.build-report-inspector": "0.2.2-preview",
"com.unity.burst": "1.4.0-preview.3",
"com.unity.cinemachine": "2.6.2",
"com.unity.burst": "1.4.0-preview.4",
"com.unity.cinemachine": "2.6.3",
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.2",
"com.unity.ide.vscode": "1.2.2",

"com.unity.render-pipelines.universal": "10.0.0-preview.26",
"com.unity.textmeshpro": "3.0.1",
"com.unity.timeline": "1.4.2",
"com.unity.timeline": "1.4.3",
"com.unity.ugui": "1.0.0",
"net.peeweek.gameplay-ingredients": "https://github.com/peeweek/net.peeweek.gameplay-ingredients.git#2019.3.0",
"com.unity.modules.ai": "1.0.0",

8
Assets/scenes/_levels/level_Island/Terrain.meta


fileFormatVersion: 2
guid: f843f542f9d13484b98e281985ec0d7d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存