概要
UnityのProfilerの情報を取得したり設定したりするときに避けては通れないProfilerDriver。
ただUnityEditorInternalに入ってるだけにどこかに使い方がまとまってたりするわけではないので、軽くよく使う項目をまとめてみました。
だいたいのことはコードに入ってるので興味ある人は覗いてみてください
動作環境
Unity 2018.1.4f1
サンプルコードのリポジトリ
UnitySandbox/ProfilerDriverSample.cs
https://github.com/KTA552/UnitySandbox/blob/develop/UnitySandbox/Assets/Scripts/Debug/ProfilerDriverSample.cs
サンプルコード
using (new EditorGUILayout.VerticalScope())
{
EditorGUILayout.Space();
EditorGUI.BeginDisabledGroup(true);
// Profilerで選択されている関数のパスを取得
var selectPath = ProfilerDriver.selectedPropertyPath;
if (selectPath == string.Empty) selectPath = "not selected.";
EditorGUILayout.LabelField("selectedPropertyPath", selectPath);
// Profilerで計測している開始と最後のフレーム数
var firstFrame = ProfilerDriver.firstFrameIndex;
var lastFrame = ProfilerDriver.lastFrameIndex;
EditorGUILayout.IntField("firstFrameIndex", firstFrame);
EditorGUILayout.IntField("lastFrameIndex", lastFrame);
// 計測対象がEditorかどうか
var isProfileEditor = ProfilerDriver.profileEditor;
// DeepProfileをしているかどうか
var isDeepProfile = ProfilerDriver.deepProfiling;
EditorGUILayout.Toggle("profileEditor", isProfileEditor);
EditorGUILayout.Toggle("deepProfiling", isDeepProfile);
var connectedProfilerCount = ProfilerDriver.connectedProfiler;
EditorGUILayout.IntField("connectedProfiler", connectedProfilerCount);
EditorGUI.EndDisabledGroup();
// Profilerの中の情報をクリア
if (GUILayout.Button("ClearAllFrames"))
{
ProfilerDriver.ClearAllFrames();
}
}