public static Profiling.Sampler Get (string name);

参数

name性能分析器采样器名称。

返回

Sampler 表示特定性能分析器标签的 Sampler 对象。

描述

返回特定 CPU 性能分析器标签的 Sampler 对象。

您可以使用此函数获取与内置标签或自定义标签关联的采样器。name 参数与您在 Profiler Window 的 Hierarchy 视图中看到的参数相同。 如果具有指定 name 参数的标签不存在或在 Player 中不可用,则返回无效的采样器对象。您可以使用 Sampler.isValid 验证采样器是否有效。

using UnityEngine;
using UnityEngine.Profiling;

public class ExampleClass : MonoBehaviour { Sampler sampler; void Start() { sampler = Sampler.Get("BehaviourUpdate"); } }

Get 可用于获取任何现有采样器(包括自定义采样器)。返回值始终为采样器类型,无法转换为 CustomSampler。

注意:目前,所有内置计数器仅在 Editor 和 Development Player 中可用。非 Development Player 中的 Get 将返回无效的采样器。

另请参阅:SamplerSampler.isValidCPU Usage Profiler