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