public static Profiling.CustomSampler Create (string name);

参数

name采样器的名称。

返回

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