public void HostAnchor(HostAnchorResults hostingResults)
    {
        Debug.Log("Hosting Anchor");

        hostingInProgress = true;

        Component worldAnchor;

        if (CreateAnchor(out worldAnchor))
        {
            Debug.Log("Point found, creating anchor");

#if !UNITY_IOS
            var hostAnchor = (Anchor)worldAnchor;
#else
            var hostAnchor = (UnityARUserAnchorComponent)worldAnchor;
#endif
            SetFloorPlane(hostAnchor.transform);
            Debug.Log("Hosting Anchor in ARKit");

            XPSession.CreateCloudAnchor(hostAnchor).ThenAction(result => {
                if (!hostingInProgress)
                {
                    return;
                }

                if (result.Response != CloudServiceResponse.Success)
                {
                    var errorString = string.Format("Failed to HOST cloud anchor: {0}.", result.Response);
                    Abort(errorString);
                    return;
                }

                Debug.Log("Hosting Complete with anchor: " + result.Anchor.CloudId);
                Debug.Log("Anchor tracking state: " + result.Anchor.TrackingState.ToString());

                Transform anchorTransform = result.Anchor.transform;
                hostingResults(anchorTransform, result.Anchor.CloudId);
                SetFloorPlane(anchorTransform);
                hostingInProgress = false;
                TrackingComplete();
            });
        }
        else
        {
            Debug.Log("Failed to host anchor");
            Abort("Failed to host anchor");
        }
    }
Esempio n. 2
0
    public void HostAnchor(HostAnchorResults hostingResults)
    {
        Debug.Log("Hosting Anchor");

        if (allPlanes.Count < 1)
        {
            Abort("No planes found yet... Try moving your device around more");
            return;
        }

        Pose anchorPose;
        bool didHit = FindPointOnPlane(out anchorPose);

        if (!didHit)
        {
            Abort("Didn't hit a plane... Point your device at plane and try again");
            return;
        }
        Debug.Log("Point found, creating anchor");

        Anchor hostAnchor = Session.CreateAnchor(anchorPose);

        SetFloorPlane(hostAnchor.transform);

        XPSession.CreateCloudAnchor(hostAnchor).ThenAction(result => {
            if (result.Response != CloudServiceResponse.Success)
            {
                var errorString = string.Format("Failed to HOST cloud anchor: {0}.", result.Response);
                Abort(errorString);
                return;
            }
            Debug.Log("Responce is: " + result.Response.ToString());

            //if (result.Anchor.TrackingState != XPTrackingState.Tracking) {
            //    var errorString = string.Format("Anchor not tracking: {0}.", result.Anchor.TrackingState.ToString());
            //    Abort(errorString);
            //    return;
            //}

            Debug.Log("Hosting Complete with anchor: " + result.Anchor.CloudId);
            Debug.Log("Anchor tracking state: " + result.Anchor.TrackingState.ToString());

            Debug.Log(result.Anchor.transform.position.ToString());

            hostingResults(result.Anchor.transform, result.Anchor.CloudId);
            TrackingComplete();
        });
    }