A ScriptableObject to associate with a RenderPipeline and store project-wide settings for that Pipeline.
A single RenderPipelineGlobalSettings instance can be registered to the GraphicsSettings via GraphicsSettings.RegisterRenderPipelineSettings. We recommend to use this ScriptableObject to save RenderPipeline settings you would find in the GraphicsSettings.
using System; using System.Collections.Generic;
using UnityEngine; using UnityEngine.Rendering;
#if UNITY_EDITOR using UnityEditor.Rendering; #endif
public class ExampleRenderPipelineAsset : RenderPipelineAsset { protected override RenderPipeline CreatePipeline() { return new ExampleRenderPipeline(); } }
public class ExampleRenderPipeline : RenderPipeline { public virtual RenderPipelineGlobalSettings globalSettings => ExampleRPGlobalSettings.instance;
protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { #if UNITY_EDITOR // On Editor we must make sure the Global Settings Asset is registered into the GraphicsSettings // Graphics Settings will make sure the asset is available on player builds if (globalSettings == null) { var mySettings = ExampleRPGlobalSettings.Create(); ExampleRPGlobalSettings.RegisterToGraphicsSettings(mySettings); } #endif
// Do something } }
[SupportedOnRenderPipeline(typeof(ExampleRenderPipelineAsset))] 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; } }
/* Use this pattern if you want to enable your global settings to use IRenderPipelineGraphicsSettings
[SerializeReference] private List<IRenderPipelineGraphicsSettings> m_SettingsList = new(); protected override List<IRenderPipelineGraphicsSettings> settingsList => m_Settings;
*/
#if UNITY_EDITOR public static void RegisterToGraphicsSettings(ExampleRPGlobalSettings newSettings) { EditorGraphicsSettings.SetRenderPipelineGlobalSettingsAsset<ExampleRenderPipeline>(newSettings as RenderPipelineGlobalSettings); cachedInstance = null; }
public static void UnregisterToGraphicsSettings() { EditorGraphicsSettings.SetRenderPipelineGlobalSettingsAsset<ExampleRenderPipeline>(null); cachedInstance = null; }
static public ExampleRPGlobalSettings Create() { ExampleRPGlobalSettings assetCreated = ScriptableObject.CreateInstance<ExampleRPGlobalSettings>(); return assetCreated; } #endif }
settingsList | Exposes a List<IRenderPipelineGraphicsSettings> that this RenderPipelineGlobalSettings instance is managing. |
Initialize | Editor-only function that initializes the RenderPipelineGlobalSettings. |
Add | Adds a IRenderPipelineGraphicsSettings interface to this instance of the RenderPipelineGlobalSettings asset. |
Contains | If the given ISRPGraphicsSetting type is present in this RenderPipelineGlobalSettings instance. |
Remove | Removes a IRenderPipelineGraphicsSettings interface from this instance of the RenderPipelineGlobalSettings asset. |
TryGet | Looks for a IRenderPipelineGraphicsSettings interface in this instance of the RenderPipelineGlobalSettings asset and returns true if it's found. |
GetInstanceID | Gets the instance ID of the object. |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
CreateInstance | 创建脚本化对象的实例。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |