您可以在创建 RenderPipelineManager.currentPipeline 正之后使用委托调用自定义代码。
当您设置 GraphicsSettings.currentRenderPipeline 或 QualitySettings.renderPipeline 时,Unity 不会立即切换渲染管线。Unity 只会在您设置一个新的 RenderPipelineAsset
之后的第一次任何 Camera 渲染时才会实例化一个新的 RenderPipeline
实例。您可以订阅此事件来了解 RenderPipeline
的创建情况。要访问当前管线对象,您可以依靠 RenderPipelineManager.currentPipeline,它会指向新创建的 RenderPipeline
。
using UnityEngine; using UnityEngine.Rendering;
public class CurrentRenderPipelineCreatedExample : MonoBehaviour { void Start() { RenderPipelineManager.activeRenderPipelineCreated += RenderPipelineManager_activeRenderPipelineCreated; }
private void OnDestroy() { RenderPipelineManager.activeRenderPipelineCreated -= RenderPipelineManager_activeRenderPipelineCreated; }
private void RenderPipelineManager_activeRenderPipelineCreated() { Debug.Log($"Render Pipeline {RenderPipelineManager.currentPipeline.GetType().Name} is created."); } }