Unity 프로파일러 모듈 커스터마이징 가이드
이 문서는 Unity의 프로파일러 모듈을 커스터마이즈하는 방법을 설명합니다. 프로파일러는 게임의 성능을 분석하고 최적화하는 데 중요한 도구입니다. 이 가이드를 통해 커스텀 모듈 세부 정보 패널을 만들고 추가 카운터를 시각화하는 방법을 배울 수 있습니다.
목차
프로파일러 모듈 세부 정보 패널 생성
프로파일러 모듈의 세부 정보 패널을 커스터마이즈하면 모듈과 관련된 추가 세부 정보를 표시하거나 성능 데이터를 커스텀 시각화할 수 있습니다. 이를 위해 기본 클래스를 사용하여 모듈 세부 정보 패널을 제어하는 스크립트를 생성합니다.
스크립트 예제
public class CustomDetailsViewController : ProfilerModuleViewController
{
public CustomDetailsViewController(ProfilerWindow profilerWindow) : base(profilerWindow) { }
protected override VisualElement CreateView()
{
// Create your UI.
}
}
모듈 세부 정보 패널 컨트롤러 스크립트 생성
모듈 세부 정보 패널을 제어하는 스크립트를 작성하여 특정 모듈을 선택할 때 모듈 세부 정보 패널에 표시되는 내용을 제어합니다.
스크립트 예제
using UnityEditor;
using UnityEditorInternal;
using Unity.Profiling.Editor;
using UnityEngine.UIElements;
public class TankEffectsDetailsViewController : ProfilerModuleViewController
{
Label m_TankTrailParticleCountLabel;
public TankEffectsDetailsViewController(ProfilerWindow profilerWindow) : base(profilerWindow) { }
protected override VisualElement CreateView()
{
var view = new VisualElement();
m_TankTrailParticleCountLabel = new Label() { style = { paddingTop = 8, paddingLeft = 8 } };
view.Add(m_TankTrailParticleCountLabel);
ReloadData();
ProfilerWindow.SelectedFrameIndexChanged += OnSelectedFrameIndexChanged;
return view;
}
protected override void Dispose(bool disposing)
{
if (!disposing)
return;
ProfilerWindow.SelectedFrameIndexChanged -= OnSelectedFrameIndexChanged;
base.Dispose(disposing);
}
void ReloadData()
{
// Retrieve the TankTrailParticleCount counter value from the Profiler as a formatted string.
var selectedFrameIndexInt32 = System.Convert.ToInt32(ProfilerWindow.selectedFrameIndex);
var value = ProfilerDriver.GetFormattedCounterValue(selectedFrameIndexInt32, GameStatistics.TanksCategory.Name, GameStatistics.TankTrailParticleCountName);
m_TankTrailParticleCountLabel.text = $"The value of '{GameStatistics.TankTrailParticleCountName}' in the selected frame is {value}.";
}
void OnSelectedFrameIndexChanged(long selectedFrameIndex)
{
ReloadData();
}
}
커스텀 UI 요소 생성
Unity의 UIToolkit을 사용하여 모듈 세부 정보 패널에 대한 커스텀 UI를 빌드할 수 있습니다. UIToolkit의 활용법에 대해서는 추가 문서를 참조하세요.
모듈 세부 정보 패널에 추가 카운터 시각화
모듈에 추가 카운터를 시각화하여 선택한 프레임에 대한 추가 데이터를 표시할 수 있습니다. 이를 위해 프로파일러에 특정 카테고리를 캡처하도록 지시하는 스크립트를 작성합니다.
스크립트 예제
using Unity.Profiling;
using Unity.Profiling.Editor;
[System.Serializable]
[ProfilerModuleMetadata("Tank Effects")]
public class TankEffectsProfilerModule : ProfilerModule
{
static readonly ProfilerCounterDescriptor[] k_Counters = new ProfilerCounterDescriptor[]
{
new ProfilerCounterDescriptor(GameStatistics.TankTrailParticleCountName, ProfilerCategory.Scripts),
new ProfilerCounterDescriptor(GameStatistics.ShellExplosionParticleCountName, ProfilerCategory.Scripts),
new ProfilerCounterDescriptor(GameStatistics.TankExplosionParticleCountName, ProfilerCategory.Scripts),
};
static readonly string[] k_AutoEnabledCategoryNames = new string[]
{
ProfilerCategory.Scripts.Name,
ProfilerCategory.Memory.Name
};
public TankEffectsProfilerModule() : base(k_Counters, autoEnabledCategoryNames: k_AutoEnabledCategoryNames) { }
}
응용 예제
- 조건부 성능 분석: 특정 게임 상황에서 성능을 분석하기 위해 커스터마이즈된 프로파일러 모듈을 활용할 수 있습니다.
- 데이터 시각화: 게임의 특정 요소(예: 총 알 수, 파티클 수 등)에 대한 시각적 자료를 제공하여 최적화에 도움을 줄 수 있습니다.
- 유저 인터페이스 개선: 더욱 직관적인 UI를 통해 성능 데이터를 더 쉽게 이해하고 사용할 수 있도록 할 수 있습니다.
이 가이드를 통해 Unity의 프로파일러를 효과적으로 커스터마이징하고, 게임의 성능을 더욱 쉽게 분석하며 최적화하는 데 도움을 받을 수 있습니다.