开始使用由 CustomSampler 的此实例定义的自定义标签分析一段代码。
这将显示在性能分析器层级视图中。
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();
}
}
Profiler.BeginSample 是使用 ConditionalAttribute 按条件编译的。
因此,在非开发版中部署时,它的开销为零。
另请参阅:CustomSampler.End、CustomSampler.Create、ProfilerCPU。