モジュールを選択すると、Profiler ウィンドウの下部にモジュール詳細パネルが表示されます。このセクションをカスタマイズして、モジュールに関連する追加の詳細を表示したり、パフォーマンスデータをカスタム製の可視化で表示したりすることができます。
Profiler モジュールのカスタムのモジュール詳細パネルを作成するには、以下を行います。
ProfilerModuleViewController 基本クラスを使用して、Profiler ウィンドウのモジュール詳細パネルをカスタマイズすることができます。これを行うには、特定のモジュールを選択するときに、モジュール詳細パネルに表示されるものを制御するスクリプトを作成します。
モジュール詳細パネルをカスタマイズするために作成するスクリプトは、以下を行う必要があります。
base(profilerWindow)
を呼び出すビューコントローラーのパブリックコンストラクターを定義します。CreateView
をオーバーライドして、カスタムモジュール詳細パネルを構築します。例:
public class CustomDetailsViewController : ProfilerModuleViewController
{
public CustomDetailsViewController(ProfilerWindow profilerWindow) : base(profilerWindow) { }
protected override VisualElement CreateView()
{
// Create your UI.
}
}
完全なモジュール詳細パネルコントローラースクリプトの例については、モジュール詳細パネルコントローラスクリプト例 を参照してください。
以下のサンプルスクリプトは、モジュール詳細パネルにテキストを表示するラベルを 1 つ描画するモジュール詳細パネルコントローラーを作成します。
このモジュールの詳細パネルコントローラーのスクリプト例では、以下を行います。
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 Toolkit を参照してください。
次のサンプル画像は、カスタム Adaptive Performance モジュールに属するカスタムモジュールの詳細パネルです。
カスタムモジュール詳細パネルを表示するには、Profiler モジュールを選択するときに、モジュール詳細パネルコントロー ラーをインスタンス化する必要があります。これを行うには、 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);
}
}
モジュールのチャートビューに含まれないカウンターを、モジュール詳細パネルに表示することができます。これは、選択したフレームの追加データを表示したい場合に便利です。
Profiler は、モジュールがアクティブなときに、モジュールのチャートビューに属するすべてのカウンターのカテゴリを自動的に取得します。追加のカウンターを取得するには、モジュールがアクティブなときに特定のカテゴリを取得するように Profiler に指示するスクリプトを記述します。
たとえば、以下のスクリプトでは、autoEnabledCategoryNames
コンストラクター引数を使用して、Scripts と Memory カテゴリを指定しています。これにより、モジュールがアクティブなときに、これらのカテゴリが有効になります。
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.