Version: 2021.1
public Unity.Profiling.ProfilerRecorderSample GetSample (int index);

描述

Gets sample data.

Use to obtain sample data.

using Unity.Profiling;
using UnityEngine;

public class FrameTimeScript : MonoBehaviour { ProfilerRecorder frameTimeRecorder;

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

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

double CalculateAverageFromSampleValuesPerFrame(ProfilerRecorder r) { int count = r.Count; double acc = 0; for (var i = 0; i < count; ++i) { acc += r.GetSample(i).Value; } return count > 0 ? acc / count : 0; }

void OnGUI() { GUI.TextArea(new Rect(10, 30, 350, 20), $"Frame time: {CalculateAverageFromSampleValuesPerFrame(frameTimeRecorder) * 1e-6:0.00}ms"); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961