Skip to content

Instantly share code, notes, and snippets.

@sapphire-al2o3
Last active January 27, 2024 15:11
Show Gist options
  • Save sapphire-al2o3/13e5bb662a947c10c463c0c593a190ab to your computer and use it in GitHub Desktop.
Save sapphire-al2o3/13e5bb662a947c10c463c0c593a190ab to your computer and use it in GitHub Desktop.
UnityでプロファイラーのCPU表示で選択している行をコピーする(Unity2018.4)
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using UnityEditorInternal.Profiling;
public class ProfilerText : Editor
{
[MenuItem("Editor/Print Profiler Text")]
static void Print()
{
string selectedPath = ProfilerDriver.selectedPropertyPath;
if (string.IsNullOrEmpty(selectedPath))
{
return;
}
var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.ProfilerWindow");
var profilerWindow = EditorWindow.GetWindow(type);
var m = type.GetMethod("GetActiveVisibleFrameIndex");
int frame = (int)m.Invoke(profilerWindow, null);
var property = new ProfilerProperty();
property.SetRoot(frame, ProfilerColumn.TotalPercent, ProfilerViewType.Hierarchy);
while (property.Next(true))
{
if (property.propertyPath.Contains(selectedPath))
{
string[] log = {
property.propertyName,
property.GetColumn(ProfilerColumn.TotalPercent),
property.GetColumn(ProfilerColumn.SelfPercent),
property.GetColumn(ProfilerColumn.Calls),
property.GetColumn(ProfilerColumn.GCMemory),
property.GetColumn(ProfilerColumn.TotalTime),
property.GetColumn(ProfilerColumn.SelfTime)
};
string text = string.Join("\t", log);
GUIUtility.systemCopyBuffer = text;
Debug.Log(text);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment