声明:本文为个人笔记,用于学习研究使用非商用,内容为个人研究及综合整理所得,若有违规,请联系,违规必改。
Unity组件——XXX组件说明
一.开发环境
Unity 无限制
VS 无限制
二.问题描述
当运行时,想知道某个具体的方法性能消耗多大时,怎么去分析?
三.解决方案原理及代码
原理
Profiler Sample,然后用系统自带的性能分析器. 菜单栏 Window-- Analysis-- Profiler 或者Ctrl+7
对应代码:
Profiler Sample是一个很好的解决方案,它是从调用Profiler.BeginSample()开始到调用 Profiler.EndSample()结束的代码块。就像这样:
using UnityEngine;
public class NeedsProfiling : MonoBehaviour
{
void Update()
{
Profiler.BeginSample("My Sample");
Debug.Log("This code is being profiled");
Profiler.EndSample();
}
}
你需要把它放在你需要分析的代码块前后。Profiler Sample将会为您记录计算时间并且它不需要深度分析就能显示在“性能分析器”窗口中。
四.总结
保持饥饿,保持愚蠢.
这世界唯一能够相信的就是你付出的努力和你走过的路.