Version: 2021.3
public long LastValue ;

描述

Gets the last value collected by the ProfilerRecorder.

Use to obtain profiler counter value or marker timing capured at the end of the last frame.

The immediate value that CurrentValue provides might be not the final value of a counter when frame ends. For example, rendering might happen after the logic finished computing the frame. Therefore, it is impossible to get the final value of draw calls until frame is fully rendered. In such cases, you can use the LastValue property for quick access to the final metric value in the last frame. The equivalent call is GetSample(Count - 1).Value.

Note:
The property requires sample storage to be non zero. Pass capacity value greater than 0 when creating ProfilerRecorder.

using Unity.Profiling;
using UnityEngine;

public class ExampleScript : MonoBehaviour { ProfilerRecorder mainThreadTimeRecorder;

static double GetRecorderFrameAverage(ProfilerRecorder recorder) { var samplesCount = recorder.Capacity; if (samplesCount == 0) return 0;

double r = 0; unsafe { var samples = stackalloc ProfilerRecorderSample[samplesCount]; recorder.CopyTo(samples, samplesCount); for (var i = 0; i < samplesCount; ++i) r += samples[i].Value; r /= samplesCount; }

return r; }

void OnEnable() { mainThreadTimeRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Internal, "Main Thread", 15); }

void OnDisable() { mainThreadTimeRecorder.Dispose(); }

void Update() { Debug.Log($"Frame Time: {GetRecorderFrameAverage(mainThreadTimeRecorder) * (1e-6f):F1} ms"); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961