Unity3D-优化之二 代码质量

来源:互联网 发布:amd游戏优化档案 编辑:程序博客网 时间:2024/06/16 06:03

代码质量


  • 运行时间
  • 垃圾回收GC Alloc
  • Unity 低效率方法
  • Unity 组件访问器
  • Profiler 定位性能热点

  1. 运行时间
public class TimeSpanManager : Singleton<TimeSpanManager>{    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();    public void Start()    {        watch.Reset();        watch.Start();    }    public void Stop(string tag)    {        watch.Stop();        TimeSpan time = watch.Elapsed;        Debug.LogError(tag+"总毫秒数:"+time.TotalMilliseconds);    }}

2.垃圾回收GC Alloc
检测GC频繁的代码

3.Unity 低效率方法
SendMessage()

4.Unity 组件访问器
this.transform、this.gameObject、this.rigidbody

5.Profiler 定位性能热点
Profiler.BeginSample()和Profiler.EndSample()

原创粉丝点击