2023-11-17 13:40:39 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Rendering;
|
2023-11-17 13:14:55 +08:00
|
|
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
|
|
namespace Code.Scripts.Gameplay.Utils
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ShadowEx
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public static void SetShadowDistance(float setDistance)
|
|
|
|
|
|
{
|
2023-11-17 13:40:39 +08:00
|
|
|
|
|
|
|
|
|
|
var urpAsset = UniversalRenderPipeline.asset;
|
2023-11-17 13:14:55 +08:00
|
|
|
|
if (urpAsset == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("无法获取URP设置资源,无法设置阴影距离");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-11-17 13:40:39 +08:00
|
|
|
|
DebugUtil.Log(urpAsset.name);
|
|
|
|
|
|
DebugUtil.Log("old shadow distance: " + urpAsset.shadowDistance);
|
2023-11-17 13:14:55 +08:00
|
|
|
|
urpAsset.shadowDistance = setDistance;
|
2023-11-17 13:40:39 +08:00
|
|
|
|
DebugUtil.Log("new shadow distance: " + urpAsset.shadowDistance);
|
|
|
|
|
|
|
|
|
|
|
|
// 更新 URP 的 Asset 实例
|
|
|
|
|
|
GraphicsSettings.renderPipelineAsset = urpAsset;
|
2023-11-17 13:14:55 +08:00
|
|
|
|
}
|
2023-11-17 13:40:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 通过旧的也设置一下
|
|
|
|
|
|
QualitySettings.shadowDistance = setDistance;
|
2023-11-17 13:14:55 +08:00
|
|
|
|
}
|
2023-11-17 13:40:39 +08:00
|
|
|
|
|
2023-11-17 13:14:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|