Version: Unity 6.0 (6000.0)
언어 : 한국어
URP에서 렌더링 디버거 활성화
URP용 렌더링 디버거 창 레퍼런스

URP의 렌더링 디버거에 컨트롤 추가

사용자 정의 컨트롤과 스크립트로 렌더링 디버거 창을 커스터마이징하여 프로젝트의 조명, 렌더링, 머티리얼 프로퍼티를 시각화할 수 있습니다.

렌더링 디버거 창은 여러 개의 탭(패널)로 구성되어 있습니다. 각 패널을 선택하면 창에 하나 이상의 컨트롤(위젯)이 표시됩니다.

위젯을 만들고 새 패널에 추가하는 방법은 다음과 같습니다.

  1. using UnityEngine.Rendering;을 사용하는 스크립트를 생성해 UnityEngine.Rendering 네임스페이스를 포함합니다.
  2. DebugUI.Widget의 자식 클래스의 인스턴스를 생성하여 위젯을 만듭니다(예: DebugUI.Button).
  3. 위젯의 값을 변경할 때 Unity가 호출하는 onValueChanged 콜백을 위젯에서 구현합니다.
  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의 자식 클래스 중 하나를 사용하여 컨테이너를 만듭니다(예: DebugUI.Foldout).
  2. 컨테이너의 Add 메서드를 사용하여 위젯 배열을 추가합니다.

다음 코드 샘플은 두 개의 체크박스가 포함된 축소 가능한 컨테이너를 생성합니다.

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용 렌더링 디버거 창 레퍼런스
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961