/// <summary> /// Get the raw image data. The returned <c>NativeArray</c> is a direct "view" into the native memory. The /// memory is only valid until this <see cref="XRAsyncCameraImageConversion"/> is disposed. /// </summary> /// <typeparam name="T">The type of data to return. No conversion is performed based on the type; this is /// merely for access convenience.</typeparam> /// <returns> /// A new <c>NativeArray</c> representing the raw image data. This method may fail; use /// <c>NativeArray.IsCreated</c> to determine the validity of the data. /// </returns> /// <exception cref="System.InvalidOperationException">Thrown if the asynchronous conversion /// <see cref="status"/> is not <see cref="AsyncCameraImageConversionStatus.Ready"/> or if the conversion is /// invalid.</exception> public unsafe NativeArray <T> GetData <T>() where T : struct { if (status != AsyncCameraImageConversionStatus.Ready) { throw new InvalidOperationException("Async request is not ready."); } IntPtr dataPtr; int dataLength; if (m_CameraSubsystem.TryGetAsyncRequestData(m_RequestId, out dataPtr, out dataLength)) { int stride = UnsafeUtility.SizeOf <T>(); var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>( (void *)dataPtr, dataLength / stride, Allocator.None); #if ENABLE_UNITY_COLLECTIONS_CHECKS NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, m_SafetyHandle); #endif return(array); } throw new InvalidOperationException("The XRAsyncCameraImageConversion is not valid."); }