Version: Unity 6.0 (6000.0)
言語 : 日本語
URP でレンダリングデバッガーを有効にする
URP の Rendering Debugger ウィンドウのリファレンス

URP でレンダリングデバッガーにコントロールを追加する

独自のコントロールやスクリプトで Rendering Debugger ウィンドウをカスタマイズし、プロジェクトのライティング、レンダリング、またはマテリアルプロパティを可視化できます。

Rendering Debugger ウィンドウには複数のタブ (‘パネル’) があります。パネルを選択すると、ウィンドウに 1 つ以上のコントロール (‘ウィジェット’) が表示されます。

ウィジェットを作成して新しいパネルに追加するには、以下の手順に従います。

  1. using UnityEngine.Rendering; を使用してスクリプトを作成し、UnityEngine.Rendering 名前空間を加えます。
  2. ウィジェットを作成するには、DebugUI.Widget の子クラス (例えば DebugUI.Button) のインスタンスを作成します。
  3. ウィジェットで、onValueChanged コールバックを実装します。ウィジェットの値を変更すると Unity がこれを呼び出します。
  4. DebugUI.instance.GetPanel を使用してパネルを作成します。
  5. ウィジェットを配列に追加します。
  6. ウィジェット配列をパネルの子リストに追加します。

配列に 2 つ以上のウィジェットを追加すると、パネルには配列と同じ順序でウィジェットが表示されます。

以下のコードサンプルは、メインのディレクショナルライトを有効または無効にするウィジェットを作成および追加します。

using UnityEngine;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System.Linq;

[ExecuteInEditMode]
public class CustomDebugPanel : MonoBehaviour
{

    static bool lightEnabled = true;

    void OnEnable()
    {
        // Create a list of widgets
        var widgetList = new List<DebugUI.Widget>();

        // Add a checkbox widget to the list of widgets
        widgetList.AddRange(new DebugUI.Widget[]
        {
            new DebugUI.BoolField
            {
                displayName = "Enable main directional light",
                tooltip = "Enable or disable the main directional light",
                getter = () => lightEnabled,

                // When the widget value is changed, change the value of lightEnabled
                setter = value => lightEnabled = value,

                // Run a custom function to enable or disable the main directional light based on the widget value
                onValueChanged = DisplaySunChanged
            },
        });

        // Create a new panel (tab) in the Rendering Debugger
        var panel = DebugManager.instance.GetPanel("My Custom Panel", createIfNull: true);

        // Add the widgets to the panel
        panel.children.Add(widgetList.ToArray());
    }

    // Remove the custom panel if the GameObject is disabled
    void OnDisable()
    {
        DebugManager.instance.RemovePanel("My Custom Panel");
    }

    // Enable or disable the main directional light based on the widget value
    void DisplaySunChanged(DebugUI.Field<bool> field, bool displaySun)
    {
        Light sun = FindObjectsOfType<Light>().Where(x => x.type == LightType.Directional).FirstOrDefault();
        if (sun)
            sun.enabled = displaySun;
    }
}

ゲームオブジェクトにスクリプトを追加します。Rendering Debugger ウィンドウに新しい My Custom Panel パネルが表示されます。

既存のパネルへのコントロールの追加

既存のパネルを取得するには、DebugManager.instance.GetPanel を使用してパネル名を指定します。createIfNullfalse に設定すると、名前が既存のパネルと一致しない場合に新しいパネルが誤って作成されることがありません。

以下のコードサンプルは、上述のコードサンプルからパネルを取得します。

var panel = DebugManager.instance.GetPanel("My Custom Panel", createIfNull: false);

URP のビルトインレンダリングデバッガパネルにウィジェットを追加しないでください。

コンテナ

コンテナを使用して、ウィジェットのグループをまとめて表示できます。

  1. DebugUI.Container の子クラスの 1 つ、例えば DebugUI.Foldout を使用してコンテナを作成します。
  2. コンテナの Add メソッドを使用してウィジェット配列を追加します。

以下のコードサンプルは、2 つのチェックボックスがある折りたたみ可能なコンテナを作成します。

using UnityEngine;
using UnityEngine.Rendering;
using System.Collections.Generic;

[ExecuteInEditMode]
public class CustomDebugPanelWithContainer : MonoBehaviour
{
    void OnEnable()
    {
        // Create a list of widgets
        var widgetList = new List<DebugUI.Widget>();

        // Add 2 checkbox widgets to the list of widgets
        widgetList.AddRange(new DebugUI.Widget[]
        {
            new DebugUI.BoolField
            {
                displayName = "Visualisation 1",
            },
            new DebugUI.BoolField
            {
                displayName = "Visualisation 2",
            },
        });

        // Create a container
        var container = new DebugUI.Foldout
        {
            displayName = "My Container"
        };

        // Add the widgets to the container
        container.children.Add(widgetList.ToArray());

        // Create a new panel (tab) in the Rendering Debugger
        var panel = DebugManager.instance.GetPanel("My Custom Panel With Container", createIfNull: true);

        // Add the container to the panel
        panel.children.Add(container);
    }
}
URP でレンダリングデバッガーを有効にする
URP の Rendering Debugger ウィンドウのリファレンス