public static NativeArray <ManagedReferenceImage> ToNativeArray(this XRReferenceImageLibrary library, Allocator allocator) { var managedReferenceImages = new NativeArray <ManagedReferenceImage>(library.count, allocator); for (var i = 0; i < library.count; ++i) { managedReferenceImages[i] = new ManagedReferenceImage(library[i]); } return(managedReferenceImages); }
public unsafe ARKitImageDatabase(XRReferenceImageLibrary serializedLibrary) { if (serializedLibrary == null) { nativePtr = UnityARKit_ImageDatabase_createEmpty(); } else { var managedReferenceImages = new NativeArray <ManagedReferenceImage>(serializedLibrary.count, Allocator.Temp); for (int i = 0; i < serializedLibrary.count; ++i) { managedReferenceImages[i] = new ManagedReferenceImage(serializedLibrary[i]); } using (managedReferenceImages) { var nativeReturnCode = UnityARKit_ImageDatabase_tryCreateFromResourceGroup( serializedLibrary.name, serializedLibrary.name.Length, serializedLibrary.guid, managedReferenceImages.GetUnsafePtr(), managedReferenceImages.Length, out IntPtr ptr); switch (nativeReturnCode) { case SetReferenceLibraryResult.Success: nativePtr = ptr; break; case SetReferenceLibraryResult.FeatureUnavailable: throw new InvalidOperationException($"Failed to resolve image library '{serializedLibrary.name}'. This feature only works on versions of ARKit 11.3 and newer."); case SetReferenceLibraryResult.ResourceDoesNotExist: throw new InvalidOperationException($"Failed to resolve image library '{serializedLibrary.name}'. There is no matching resource group, or the resource group does not contain any reference images."); default: throw new InvalidOperationException($"Unexpected return code {nativeReturnCode} encountered while trying to create a reference image library with name {serializedLibrary.name}."); } } } }
static extern unsafe bool UnityARKit_ImageDatabase_AddImage( IntPtr database, void *bytes, TextureFormat format, int width, int height, float physicalWidth, ref ManagedReferenceImage managedReferenceImage);