コード例 #1
0
        public GoogleARCore.AsyncTask <CloudAnchorResult> CreateCloudAnchor(
            UnityEngine.Pose pose, int ttlDays)
        {
            Action <CloudAnchorResult> onComplete;

            GoogleARCore.AsyncTask <CloudAnchorResult> task;
            if (!CreateCloudAnchorResultAsyncTask(out onComplete, out task))
            {
                return(task);
            }

            // Create an native Pose and Anchor.
            var    poseHandle        = LifecycleManager.Instance.NativeSession.PoseApi.Create(pose);
            IntPtr arkitAnchorHandle = IntPtr.Zero;

            ExternApi.ARKitAnchor_create(poseHandle, ref arkitAnchorHandle);

            CreateCloudAnchor(onComplete, arkitAnchorHandle, ttlDays);

            // Clean up handles for the Pose and ARKitAnchor.
            LifecycleManager.Instance.NativeSession.PoseApi.Destroy(poseHandle);
            ExternApi.ARKitAnchor_release(arkitAnchorHandle);

            return(task);
        }
コード例 #2
0
        public GoogleARCore.AsyncTask <CloudAnchorResult> CreateCloudAnchor(UnityEngine.Pose pose)
        {
            Action <CloudAnchorResult> onComplete;
            var task = new GoogleARCore.AsyncTask <CloudAnchorResult>(out onComplete);

            if (LifecycleManager.Instance.NativeSession == null)
            {
                onComplete(new CloudAnchorResult()
                {
                    Response = CloudServiceResponse.ErrorNotSupportedByConfiguration,
                    Anchor   = null,
                });

                return(task);
            }

            var    poseHandle        = LifecycleManager.Instance.NativeSession.PoseApi.Create(pose);
            IntPtr arkitAnchorHandle = IntPtr.Zero;

            ExternApi.ARKitAnchor_create(poseHandle, ref arkitAnchorHandle);

            IntPtr cloudAnchorHandle = IntPtr.Zero;
            var    status            = LifecycleManager.Instance.NativeSession.SessionApi
                                       .CreateCloudAnchor(arkitAnchorHandle, out cloudAnchorHandle);

            LifecycleManager.Instance.NativeSession.PoseApi.Destroy(poseHandle);
            ExternApi.ARKitAnchor_release(arkitAnchorHandle);

            if (status != ApiArStatus.Success)
            {
                onComplete(new CloudAnchorResult()
                {
                    Response = status.ToCloudServiceResponse(),
                    Anchor   = null,
                });

                return(task);
            }

            var request = new CloudAnchorRequest()
            {
                IsComplete     = false,
                NativeSession  = LifecycleManager.Instance.NativeSession,
                AnchorHandle   = cloudAnchorHandle,
                OnTaskComplete = onComplete,
            };

            _UpdateCloudAnchorRequest(request, true);
            return(task);
        }