moduleIdentifier | 您要检索其选择控制器的 Profiler 模块标识符。目前,只有 ProfilerWindow.cpuModuleIdentifier 和 ProfilerWindow.gpuModuleIdentifier 有效,其他选项将抛出 ArgumentException。 |
IProfilerFrameTimeViewSampleSelectionController 一个 IProfilerFrameTimeViewSampleSelectionController 对象,您可以使用它来控制指定 Profiler 模块的选择。
检索一个 IProfilerFrameTimeViewSampleSelectionController 对象,您可使用它来控制显示 Profiler 样品的计时信息(如 CPU 使用率模块 和 GPU 使用率 Profiler 模块)的 Profiler 模块 中的选择。
using UnityEditor; using UnityEditor.Profiling; using UnityEngine;
public class Example : EditorWindow { ProfilerWindow m_Profiler = null; [MenuItem("Window/Analysis/Profiler Extension")] public static void ShowExampleWindow() { var window = GetWindow<Example>(); window.m_Profiler = EditorWindow.GetWindow<ProfilerWindow>(); }
void OnGUI() { // First make sure there is an open Profiler Window if (m_Profiler == null) m_Profiler = EditorWindow.GetWindow<ProfilerWindow>(); // If the currently selected Module is not the CPU Usage module, setting the selection will not be visible to the user immediately if (m_Profiler.selectedModuleIdentifier == ProfilerWindow.cpuModuleIdentifier) { // Get the CPU Usage Profiler module's selection controller interface to interact with the selection var cpuSampleSelectionController = m_Profiler.GetFrameTimeViewSampleSelectionController(ProfilerWindow.cpuModuleIdentifier); // If the current selection object is null, there is no selection to print out. using (new EditorGUI.DisabledScope(cpuSampleSelectionController.selection == null)) { if (GUILayout.Button("Print current Selection")) { // Get the currently shown selection and log out some of its details var selection = cpuSampleSelectionController.selection; Debug.Log($"The sample currently selected in the CPU Usage Profiler module is {selection.sampleDisplayName} at a depth of {selection.markerPathDepth}."); } } } } }