表示 ProfilerMarkerData.Ptr 指向一个 char*。
使用 String16 可以将字符串数据传递给 ProfilerUnsafeUtility.BeginSampleWithMetadata。
注意:字符串大小必须按字节设置,其中包括空终止符。
using System.Diagnostics; using System.Runtime.CompilerServices; using Unity.Profiling; using Unity.Profiling.LowLevel; using Unity.Profiling.LowLevel.Unsafe;
public static class ProfilerMarkerExtension { [MethodImpl(MethodImplOptions.AggressiveInlining)] [Conditional("ENABLE_PROFILER")] public static unsafe void Begin(this ProfilerMarker marker, string metadata) { var data = new ProfilerMarkerData(); data.Type = (byte)ProfilerMarkerDataType.String16; fixed(char* c = metadata) { data.Size = ((uint)metadata.Length + 1) * 2; data.Ptr = c; ProfilerUnsafeUtility.BeginSampleWithMetadata(marker.Handle, 1, &data); } } }