Version: 2020.2
public static Profiling.CustomSampler Create (string name, bool collectGpuData);

参数

name 采样器的名称。
collectGpuData Specifies whether this Sampler records GPU timings. If you want the Sampler to record GPU timings, set this to true.

返回

CustomSampler CustomSampler 对象,如果存在具有相同名称的内置采样器,则返回 null

描述

创建一个用于分析代码的各个部分的新 CustomSampler。

采用相同 name 参数的多次调用将返回不同的 CustomSampler 对象,这些对象引用同一本机表示。 CustomSampler 表示脚本性能分析器标签。

当与 null 字符串结合使用时,方法将抛出 ArgumentNullException

using UnityEngine;
using UnityEngine.Profiling;

public class ExampleClass : MonoBehaviour { CustomSampler sampler; void Start() { sampler = CustomSampler.Create("MyCustomSampler"); }

void Update() { sampler.Begin(); // do something that takes a lot of time sampler.End(); } }

另请参阅:CustomSampler.BeginSampler.Get