Version: 2020.3

GraphicsSettings.currentRenderPipeline

切换到手册
public static Rendering.RenderPipelineAsset currentRenderPipeline ;

描述

The RenderPipelineAsset that defines the active render pipeline for the current quality level.

The active render pipeline is the render pipeline that Unity is currently using to render your application and parts of the Editor such as the Scene view and Game view. The active render pipeline can be a default value, or you can set override values for different quality levels.

The default value is defined in GraphicsSettings.defaultRenderPipeline. The override value for the current quality level is defined in QualitySettings.renderPipeline.

If the default value is not defined, then the active render pipeline is the Built-in Render Pipeline. Otherwise, if an override value is defined for the current quality level, the active render pipeline is the override value; if no override value is defined for the current quality level, it is the default value.

using UnityEngine;
using UnityEngine.Rendering;
 
public class ActiveRenderPipelineExample : MonoBehaviour
{
    // In the Inspector, assign a Render Pipeline Asset to each of these fields
    public RenderPipelineAsset defaultRenderPipelineAsset;
    public RenderPipelineAsset overrideRenderPipelineAsset;
 
    void Start()
    {
        GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset;
        QualitySettings.renderPipeline = overrideRenderPipelineAsset;

DisplayCurrentRenderPipeline(); }

void Update() { // When the user presses the left shift key, switch the default render pipeline if (Input.GetKeyDown(KeyCode.LeftShift)) { SwitchDefaultRenderPipeline(); DisplayCurrentRenderPipeline(); } // When the user presses the right shift key, switch the override render pipeline else if (Input.GetKeyDown(KeyCode.RightShift)) { SwitchOverrideRenderPipeline(); DisplayCurrentRenderPipeline(); } }

// Switch the default render pipeline between null, // and the render pipeline defined in defaultRenderPipelineAsset void SwitchDefaultRenderPipeline() { if (GraphicsSettings.defaultRenderPipeline == defaultRenderPipelineAsset) { GraphicsSettings.defaultRenderPipeline = null; } else { GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset; } }

// Switch the override render pipeline between null, // and the render pipeline defined in overrideRenderPipelineAsset void SwitchOverrideRenderPipeline() { if (QualitySettings.renderPipeline == overrideRenderPipelineAsset) { QualitySettings.renderPipeline = null; } else { QualitySettings.renderPipeline = overrideRenderPipelineAsset; } }

// Print the current render pipeline information to the console void DisplayCurrentRenderPipeline() { // GraphicsSettings.defaultRenderPipeline determines the default render pipeline // If it is null, the default is the Built-in Render Pipeline if (GraphicsSettings.defaultRenderPipeline != null) { Debug.Log("The default render pipeline is defined by " + GraphicsSettings.defaultRenderPipeline.name); } else { Debug.Log("The default render pipeline is the Built-in Render Pipeline"); }

// QualitySettings.renderPipeline determines the override render pipeline for the current quality level // If it is null, no override exists for the current quality level if (QualitySettings.renderPipeline != null) { Debug.Log("The override render pipeline for the current quality level is defined by " + QualitySettings.renderPipeline.name); } else { Debug.Log("No override render pipeline exists for the current quality level"); }

// If the default render pipeline is the Built-in Render Pipeline, Unity always uses that. // Otherwise, if an override render pipeline is defined, Unity uses that. // If an override render pipeline is not defined, it falls back to the default value if (GraphicsSettings.defaultRenderPipeline == null) { Debug.Log("The active render pipeline is the default render pipeline"); } else if (QualitySettings.renderPipeline != null) { Debug.Log("The active render pipeline is the override render pipeline"); } else { Debug.Log("The active render pipeline is the default render pipeline"); }

// To get a reference to the Render Pipeline Asset that defines the active render pipeline, // without knowing if it is the default or an override, use GraphicsSettings.currentRenderPipeline if (GraphicsSettings.currentRenderPipeline != null) { Debug.Log("The active render pipeline is defined by " + GraphicsSettings.currentRenderPipeline.name); } else { Debug.Log("The active render pipeline is the Built-in Render Pipeline"); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961