private void CloudManager_AnchorLocated(object sender, AnchorLocatedEventArgs args) { QueueOnUpdate(new Action(() => Debug.Log($"Anchor recognized as a possible Azure anchor"))); if (args.Status == LocateAnchorStatus.Located || args.Status == LocateAnchorStatus.AlreadyTracked) { currentCloudAnchor = args.Anchor; QueueOnUpdate(() => { Debug.Log($"Azure anchor located successfully"); // Notify AnchorFeedbackScript OnASAAnchorLocated?.Invoke(); #if UNITY_ANDROID || UNITY_IOS Pose anchorPose = Pose.identity; anchorPose = currentCloudAnchor.GetPose(); #endif #if WINDOWS_UWP || UNITY_WSA // HoloLens: The position will be set based on the unityARUserAnchor that was located. // Create a local anchor at the location of the object in question gameObject.CreateNativeAnchor(); // Notify AnchorFeedbackScript OnCreateLocalAnchor?.Invoke(); // On HoloLens, if we do not have a cloudAnchor already, we will have already positioned the // object based on the passed in worldPos/worldRot and attached a new world anchor, // so we are ready to commit the anchor to the cloud if requested. // If we do have a cloudAnchor, we will use it's pointer to setup the world anchor, // which will position the object automatically. if (currentCloudAnchor != null) { Debug.Log("Local anchor position successfully set to Azure anchor position"); gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(currentCloudAnchor.LocalAnchor); } #else Debug.Log($"Setting object to anchor pose with position '{anchorPose.position}' and rotation '{anchorPose.rotation}'"); transform.position = anchorPose.position; transform.rotation = anchorPose.rotation; // Create a native anchor at the location of the object in question gameObject.CreateNativeAnchor(); // Notify AnchorFeedbackScript OnCreateLocalAnchor?.Invoke(); #endif }); } else { QueueOnUpdate(new Action(() => Debug.Log($"Attempt to locate Anchor with ID '{args.Identifier}' failed, locate anchor status was not 'Located' but '{args.Status}'"))); } }
private void CloudManager_OnAnchorLocated(object sender, AnchorLocatedEventArgs args) { Debug.LogFormat("Anchor recognized as a possible anchor {0} {1}", args.Identifier, args.Status); if (args.Status == LocateAnchorStatus.Located) { OnCloudAnchorLocated(args); OnASAAnchorLocated?.Invoke(); Debug.Log("Anchor Located!"); } }