GetSettingsForRenderPipeline
Get the registered RenderPipelineGlobalSettings for the given RenderPipeline.
Read time 2 minutesLast updated 11 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Rendering
- Assembly: UnityEngine.CoreModule
GetSettingsForRenderPipeline<T>()
Get the registered RenderPipelineGlobalSettings for the given RenderPipeline.
public static RenderPipelineGlobalSettings GetSettingsForRenderPipeline<T>() where T : RenderPipeline
Returns
Type | Description |
|---|---|
| RenderPipelineGlobalSettings | RenderPipelineGlobalSettings asset that is registered for the given pipeline. |
Remarks
This method iterates over all RenderPipelineGlobalSettings registered in the GraphicsSettings. If there is an instance registered for the given RenderPipeline, the method returns it, otherwise the method returns null. The function performs string comparison and may allocate memory. To improve runtime performance, cache the result of the function call.
Examples
using UnityEngine;using UnityEngine.Rendering;public class ExampleRenderPipelineAsset : RenderPipelineAsset{ protected override RenderPipeline CreatePipeline() { return new ExampleRenderPipeline(); }}public class ExampleRenderPipeline : RenderPipeline{ public ExampleRenderPipeline() { var mySettings = ExampleRPGlobalSettings.Create(); ExampleRPGlobalSettings.RegisterToGraphicsSettings(mySettings); } protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { // Do something } public virtual RenderPipelineGlobalSettings globalSettings { get { return ExampleRPGlobalSettings.instance; } } protected virtual void Dispose(bool disposing) { ExampleRPGlobalSettings.UnregisterToGraphicsSettings(); }}public class ExampleRPGlobalSettings : RenderPipelineGlobalSettings{ private static ExampleRPGlobalSettings cachedInstance = null; public static ExampleRPGlobalSettings instance { get { if (cachedInstance == null) cachedInstance = GraphicsSettings.GetSettingsForRenderPipeline<ExampleRenderPipeline>() as ExampleRPGlobalSettings; return cachedInstance; } } public static void RegisterToGraphicsSettings(ExampleRPGlobalSettings newSettings) { GraphicsSettings.RegisterRenderPipelineSettings<ExampleRenderPipeline>(newSettings as RenderPipelineGlobalSettings); cachedInstance = null; } public static void UnregisterToGraphicsSettings() { GraphicsSettings.UnregisterRenderPipelineSettings<ExampleRenderPipeline>(); cachedInstance = null; } static public ExampleRPGlobalSettings Create() { ExampleRPGlobalSettings assetCreated = ScriptableObject.CreateInstance<ExampleRPGlobalSettings>(); return assetCreated; }}
GetSettingsForRenderPipeline(Type)
Get the registered RenderPipelineGlobalSettings for the given RenderPipeline.
public static RenderPipelineGlobalSettings GetSettingsForRenderPipeline(Type renderPipelineType)
Parameters
The type of RenderPipeline.
Returns
Type | Description |
|---|---|
| RenderPipelineGlobalSettings | RenderPipelineGlobalSettings asset that is registered for the given pipeline. |
Remarks
This method iterates over all RenderPipelineGlobalSettings registered in the GraphicsSettings. If there is an instance registered for the given RenderPipeline, the method returns it, otherwise the method returns null. The function performs string comparison and may allocate memory. To improve runtime performance, cache the result of the function call.
Examples
using UnityEngine;using UnityEngine.Rendering;public class ExampleRenderPipelineAsset : RenderPipelineAsset{ protected override RenderPipeline CreatePipeline() { return new ExampleRenderPipeline(); }}public class ExampleRenderPipeline : RenderPipeline{ public ExampleRenderPipeline() { var mySettings = ExampleRPGlobalSettings.Create(); ExampleRPGlobalSettings.RegisterToGraphicsSettings(mySettings); } protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { // Do something } public virtual RenderPipelineGlobalSettings globalSettings { get { return ExampleRPGlobalSettings.instance; } } protected virtual void Dispose(bool disposing) { ExampleRPGlobalSettings.UnregisterToGraphicsSettings(); }}public class ExampleRPGlobalSettings : RenderPipelineGlobalSettings{ private static ExampleRPGlobalSettings cachedInstance = null; public static ExampleRPGlobalSettings instance { get { if (cachedInstance == null) cachedInstance = GraphicsSettings.GetSettingsForRenderPipeline<ExampleRenderPipeline>() as ExampleRPGlobalSettings; return cachedInstance; } } public static void RegisterToGraphicsSettings(ExampleRPGlobalSettings newSettings) { GraphicsSettings.RegisterRenderPipelineSettings<ExampleRenderPipeline>(newSettings as RenderPipelineGlobalSettings); cachedInstance = null; } public static void UnregisterToGraphicsSettings() { GraphicsSettings.UnregisterRenderPipelineSettings<ExampleRenderPipeline>(); cachedInstance = null; } static public ExampleRPGlobalSettings Create() { ExampleRPGlobalSettings assetCreated = ScriptableObject.CreateInstance<ExampleRPGlobalSettings>(); return assetCreated; }}