指定标记存在于非开发版 Player 中。
使用 AvailabilityNonDevelopment 来确定分析器标记或计数器在非开发版 Player 中是否可用。
using System.Collections.Generic; using Unity.Profiling.LowLevel; using Unity.Profiling.LowLevel.Unsafe;
public class Example { public static unsafe void WriteAllNonDevelopmentStatsToFile(string filePath) { using (var writer = new System.IO.StreamWriter(filePath)) { var availableStatHandles = new List<ProfilerRecorderHandle>(); ProfilerRecorderHandle.GetAvailable(availableStatHandles); foreach (var h in availableStatHandles) { var statDesc = ProfilerRecorderHandle.GetDescription(h); if (!statDesc.Flags.HasFlag(MarkerFlags.AvailabilityNonDevelopment)) continue;
var name = System.Text.Encoding.UTF8.GetString(statDesc.NameUtf8, statDesc.NameUtf8Len); writer.WriteLine($"{name};{statDesc.Flags}"); } } } }
使用 AvailabilityNonDevelopment 表示使用 ProfilerUnsafeUtility.CreateMarker 编写的分析器标记在非开发版 Player 中可用。
using Unity.Collections.LowLevel.Unsafe; using Unity.Profiling.LowLevel; using Unity.Profiling.LowLevel.Unsafe; using System;
class Example { static readonly IntPtr markerHandle = ProfilerUnsafeUtility.CreateMarker("MyMarker", ProfilerUnsafeUtility.CategoryScripts, MarkerFlags.AvailabilityNonDevelopment, 0); static unsafe void DoWork(int num) { ProfilerUnsafeUtility.BeginSample(markerHandle); //... ProfilerUnsafeUtility.EndSample(markerHandle); } }
注意
AvailabilityNonDevelopment 标志对 ProfilerMarker 的创建没有影响,因为 ProfilerMarker API 仅针对开发版 Player。