工程里UniversalRenderPipelineAsset可能有好几种(比如low、mid、high等),游戏运行时会根据机型动态加载指定的UniversalRenderPipelineAsset,以下代码可以动态获取当前使用的UniversalRenderPipelineAsset具体是哪个,然后动态修改阴影等别的参数:
- UniversalRenderPipelineAsset m_URPAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
- if (m_URPAsset != null)
- {
- m_DefaultDistance = m_URPAsset.shadowDistance;
- m_URPAsset.shadowDistance = m_ShadowDistance;
- }
上面代码在Start函数里只能获取默认的UniversalRenderPipelineAsset,而不是当前实际运行的UniversalRenderPipelineAsset,我这边的做法是在协程里等了一帧去获取:
- private IEnumerator IEResetShadows()
- {
- //第一帧的时候获取的是默认的pipeline
- yield return null;
- // 动态设置阴影距离
- UniversalRenderPipelineAsset m_URPAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;
- if (m_URPAsset != null)
- {
- m_DefaultDistance = m_URPAsset.shadowDistance;
- m_URPAsset.shadowDistance = m_ShadowDistance;
- }
- }