unity-打tag技巧

unity 性能优化中查找性能瓶颈的一个小技巧


  • 利用 profiler 中的 快照功能,可以在某一帧中打个标记,然后在 profiler 中看如果性能出现瓶颈的时候是否存在那个标记。但是这样也只能确定在这一帧有问题,并不能确定是哪里有问题,因为这个 tag 没有顺序排序。

    1
    2
    3
    4
    5
    6
    public static bool DebugTag(string tag) {
    UnityEngine.Profiling.Profiler.BeginSample(tag);
    Debugger.Log("--- debugtag, {0}", tag);
    UnityEngine.Profiling.Profiler.EndSample();
    return true;
    }
  • 通过在模型的异步加载的回调用打 Tag 可以看出都是在异步加载完后的实例化过程造成的 波峰

    这里写图片描述

    这里写图片描述

    这里写图片描述

    • 有时在同一帧回调回来 实例化