모듈을 선택하면 프로파일러 창 하단에 모듈 세부 정보 패널이 나타납니다. 이 섹션을 커스터마이즈하여 모듈과 관련된 추가 세부 정보를 표시하거나 성능 데이터의 커스텀 시각화를 표시할 수 있습니다.
프로파일러 모듈에 대한 커스텀 모듈 세부 정보 패널을 생성하려면 다음을 수행합니다.
ProfilerModuleViewController 기본 클래스를 사용하여 프로파일러 창에서 모듈 세부 정보 패널을 커스터마이즈할 수 있습니다. 이렇게 하려면 특정 모듈을 선택할 때 모듈 세부 정보 패널에 표시되는 내용을 제어하는 스크립트를 만듭니다.
모듈 세부 정보 패널을 커스터마이즈하기 위해 생성하는 스크립트는 다음을 충족해야 합니다.
base(profilerWindow)
를 호출하는 뷰 컨트롤러에 대한 공용 생성자를 정의합니다.CreateView
를 오버라이드하여 커스텀 모듈 세부 정보 패널을 빌드합니다.예제:
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
{
// Define a label, which will display the total particle count for tank trails in the selected frame.
Label m_TankTrailParticleCountLabel;
// Define a constructor for the view controller, which calls the base constructor with the Profiler Window passed from the module.
public TankEffectsDetailsViewController(ProfilerWindow profilerWindow) : base(profilerWindow) { }
// Override CreateView to build the custom module details panel.6666666667reateView()
{
var view = new VisualElement();
// Create the label and add it to the view.
m_TankTrailParticleCountLabel = new Label() { style = { paddingTop = 8, paddingLeft = 8 } };
view.Add(m_TankTrailParticleCountLabel);
// Populate the label with the current data for the selected frame.
ReloadData();
// Be notified when the selected frame index in the Profiler Window changes, so we can update the label.
ProfilerWindow.SelectedFrameIndexChanged += OnSelectedFrameIndexChanged;
return view;
}
// Override Dispose to do any cleanup of the view when it is destroyed. This is a standard C# Dispose pattern.
protected override void Dispose(bool disposing)
{
if (!disposing)
return;
// Unsubscribe from the Profiler window event that we previously subscribed to.
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);
// Update the label's text with the value.
m_TankTrailParticleCountLabel.text = $"The value of '{GameStatistics.TankTrailParticleCountName}' in the selected frame is {value}.";
}
void OnSelectedFrameIndexChanged(long selectedFrameIndex)
{
// Update the label with the current data for the newly selected frame.
ReloadData();
}
}
Unity의 UIToolkit을 사용하여 모듈 세부 정보 패널에 대한 커스텀 UI를 빌드할 수 있습니다. 자세한 내용은 UI 툴킷을 참조하십시오.
다음 예시 이미지는 커스텀 Adaptive Performance 모듈에 속하는 커스텀 모듈 세부 정보 패널을 보여줍니다.
커스텀 모듈 세부 정보 패널을 표시하려면 프로파일러 모듈을 선택할 때 모듈 세부 정보 패널 컨트롤러를 인스턴스화해야 합니다. 이렇게 하려면 CreateDetailsViewController
를 오버라이드하여 새 모듈 세부 정보 패널 컨트롤러를 생성하고 작성합니다. 그런 다음 Unity는 모듈의 세부 정보 패널을 표시할 때 이 메서드를 호출합니다.
다음 코드 예제는 TankEffectsProfilerModule
이라는 모듈에 대한 커스텀 모듈 세부 정보 패널을 인스턴스화합니다.
using Unity.Profiling.Editor;
[System.Serializable]
[ProfilerModuleMetadata("Tank Effects")]
public class TankEffectsProfilerModule : ProfilerModule
{
static readonly ProfilerCounterDescriptor[] k_Counters = new ProfilerCounterDescriptor[]
{
new ProfilerCounterDescriptor(GameStatistics.TankTrailParticleCountName, GameStatistics.TanksCategory),
new ProfilerCounterDescriptor(GameStatistics.ShellExplosionParticleCountName, GameStatistics.TanksCategory),
new ProfilerCounterDescriptor(GameStatistics.TankExplosionParticleCountName, GameStatistics.TanksCategory),
};
public TankEffectsProfilerModule() : base(k_Counters) { }
public override ProfilerModuleViewController CreateDetailsViewController()
{
return new TankEffectsDetailsViewController(ProfilerWindow);
}
}
모듈의 차트 뷰에 포함되지 않은 카운터를 모듈 세부 정보 패널에 표시할 수 있습니다. 선택한 프레임에 대한 추가 데이터를 표시하려는 경우에 유용합니다.
프로파일러는 액티브 상태인 모듈의 차트 뷰에 속하는 모든 카운터의 카테고리를 자동으로 캡처합니다. 추가 카운터를 캡처하려면 모듈이 액티브 상태일 때 특정 카테고리를 캡처하도록 프로파일러에 지시하는 스크립트를 작성합니다.
예를 들어 아래 스크립트는 autoEnabledCategoryNames
생성자 인자를 사용하여 스크립트와 메모리 카테고리를 지정합니다. 이렇게 하면 모듈이 액티브 상태일 때 지정된 카테고리가 활성화됩니다.
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),
};
// Enable the ProfilerCategory.Scripts and ProfilerCategory.Memory categories when the module is active.
static readonly string[] k_AutoEnabledCategoryNames = new string[]
{
ProfilerCategory.Scripts.Name,
ProfilerCategory.Memory.Name
};
// Pass the auto-enabled category names to the base constructor.
public TankEffectsProfilerModule() : base(k_Counters, autoEnabledCategoryNames: k_AutoEnabledCategoryNames) { }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.