版本:Unity 6 (6000.0)
语言中文
  • C#

GraphicsSettings.GetSettingsForRenderPipeline

建议更改

成功!

感谢你帮助我们改进 Unity 文档的质量。虽然我们无法接受所有投稿,但我们会阅读用户建议的每项更改,并在适当的地方进行更新。

关闭

提交失败

由于某种原因,无法提交你的建议更改。请在几分钟后<a>重试</a>。感谢你花时间帮助我们改进 Unity 文档的质量。

关闭

取消

声明

public static Rendering.RenderPipelineGlobalSettings GetSettingsForRenderPipeline(Type renderPipelineType);

声明

public static Rendering.RenderPipelineGlobalSettings GetSettingsForRenderPipeline();

参数

renderPipelineType RenderPipeline 的类型。

返回

针对给定管道注册的 RenderPipelineGlobalSettings RenderPipelineGlobalSettings 资产。

说明

获取针对给定 RenderPipeline 已注册的 RenderPipelineGlobalSettings

此方法会遍历 GraphicsSettings 中注册的所有 RenderPipelineGlobalSettings。如果为特定 RenderPipeline 注册了一个实例,此方法会将其返回,否则该方法会返回 null。此函数执行字符串比较并可能会分配内存。为提高运行时性能,应缓存函数调用的结果。

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; } }