Пример #1
0
        public unsafe ARCoreImageDatabase(XRReferenceImageLibrary serializedLibrary)
        {
            if (serializedLibrary == null)
            {
                m_Self = Deserialize(default(NativeView), default(NativeView));
            }
            else
            {
                using (var webRequest = new UnityWebRequest(ARCoreImageTrackingSubsystem.GetPathForLibrary(serializedLibrary)))
                {
                    webRequest.downloadHandler = new DownloadHandlerBuffer();
                    webRequest.disposeDownloadHandlerOnDispose = true;
                    webRequest.SendWebRequest();
                    while (!webRequest.isDone)
                    {
                    }

                    byte[] libraryBlob = webRequest.downloadHandler.data;
                    if (libraryBlob == null || libraryBlob.Length == 0)
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "Failed to load image library '{0}' - file was empty!", serializedLibrary.name));
                    }

                    var managedReferenceImages = new NativeArray <ManagedReferenceImage>(serializedLibrary.count, Allocator.Temp);
                    try
                    {
                        for (int i = 0; i < serializedLibrary.count; ++i)
                        {
                            managedReferenceImages[i] = new ManagedReferenceImage(serializedLibrary[i]);
                        }

                        fixed(byte *blob = libraryBlob)
                        {
                            m_Self = Deserialize(new NativeView(blob, libraryBlob.Length), NativeView.Create(managedReferenceImages));
                        }
                    }
                    finally
                    {
                        managedReferenceImages.Dispose();
                    }
                }
            }
        }
Пример #2
0
        static byte[] GetLibraryData(XRReferenceImageLibrary library)
        {
            // 4.2+
            if (library.dataStore.TryGetValue(dataStoreKey, out var bytes))
            {
                return(bytes);
            }

            // Pre 4.2 fallback
            using var webRequest = new UnityWebRequest(ARCoreImageTrackingSubsystem.GetPathForLibrary(library))
                  {
                      downloadHandler = new DownloadHandlerBuffer(),
                      disposeDownloadHandlerOnDispose = true
                  };

            webRequest.SendWebRequest();
            while (!webRequest.isDone)
            {
            }

            return(webRequest.downloadHandler.data);
        }