사용자 정의 컨트롤과 스크립트로 렌더링 디버거 창을 커스터마이징하여 프로젝트의 조명, 렌더링, 머티리얼 프로퍼티를 시각화할 수 있습니다.
렌더링 디버거 창은 여러 개의 탭(패널)로 구성되어 있습니다. 각 패널을 선택하면 창에 하나 이상의 컨트롤(위젯)이 표시됩니다.
위젯을 만들고 새 패널에 추가하는 방법은 다음과 같습니다.
using UnityEngine.Rendering;을 사용하는 스크립트를 생성해 UnityEngine.Rendering 네임스페이스를 포함합니다.DebugUI.Button).onValueChanged 콜백을 위젯에서 구현합니다.배열에 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를 사용합니다. createIfNull을 false로 설정하여 이름이 기존 패널과 일치하지 않을 경우 새 패널이 생성되지 않게 합니다.
다음 코드 샘플은 위의 코드 샘플에서 패널을 가져옵니다.
var panel = DebugManager.instance.GetPanel("My Custom Panel", createIfNull: false);
위젯을 URP의 빌트인 렌더링 디버거 패널에 추가해서는 안 됩니다.
컨테이너를 사용하여 위젯 그룹을 함께 표시할 수 있습니다.
DebugUI.Foldout).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);
}
}