id | Unique identifier associated with the data. |
tag | Data stream index. |
index | Chunk index. |
NativeArray<T> Returns the session metadata as a NativeArray.
Retrieves the metadata of the session this frame occurred in as a NativeArray.
Use GetSessionMetaData to retrieve the data that the Profiler.EmitSessionMetaData method wrote to the Profiler stream.
Profiler data can contain frames from different sessions.
Use id to identify the metadata from your Project or package.
Use tag to distinguish between different data streams.
Use index to retrieve separate data chunks for each Profiler.EmitSessionMetaData called during the profiling session.
using System; using Unity.Collections; using UnityEditor.Profiling; using UnityEditorInternal; using UnityEngine; using UnityEngine.Profiling;
public class Example { public struct TextureInfo { public int format; public int w; public int h; }
public static readonly Guid MyProjectId = new Guid("7E1DEA84-51F1-477A-82B5-B5C57AC1EBF7"); public static readonly int TextureInfoTag = 0; public static readonly int TextureDataTag = 1;
public void EmitTextureToProfilerStream(Texture2D t) { TextureInfo textureInfo = new TextureInfo() { format = (int)t.format, w = t.width, h = t.height }; NativeArray<byte> textureData = t.GetRawTextureData<byte>(); Profiler.EmitSessionMetaData(MyProjectId, TextureInfoTag, new[] { textureInfo }); Profiler.EmitSessionMetaData(MyProjectId, TextureDataTag, textureData); }
public Texture2D GetSessionTextureFromProfilerStream(int frame) { using (var frameData = ProfilerDriver.GetRawFrameDataView(frame, 0)) { NativeArray<TextureInfo> textureInfos = frameData.GetSessionMetaData<TextureInfo>(MyProjectId, TextureInfoTag); if (textureInfos.Length == 0) return null;
NativeArray<byte> textureData = frameData.GetSessionMetaData<byte>(MyProjectId, TextureDataTag); if (textureData.Length == 0) return null;
TextureInfo textureInfo = textureInfos[0]; Texture2D texture = new Texture2D(textureInfo.w, textureInfo.h, (TextureFormat)textureInfo.format, false); texture.LoadRawTextureData(textureData);
return texture; } } }
Note:
The FrameDataView instance defines the lifetime of the returned ''NativeArray'. As such, if FrameDataView is disposed, all returned metadata becomes invalid and cannot be used. Copy data to a new NativeArray if you need it for longer duration.
See Also: Profiler.EmitSessionMetaData.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.