private void SpawnOrMoveCurrentAnchoredObject(CloudSpatialAnchor foundAnchor) { if (localAnchorGameObject is null) { InstantiateLocalGameObject(Pose.identity.position, Pose.identity.rotation); } // Get anchor position. #if UNITY_ANDROID || UNITY_IOS Pose anchorPose = foundAnchor.GetAnchorPose(); Debug.Log("ASA log: new position:" + anchorPose.position); localAnchorGameObject.GetComponent <DragonAI>().ChangePosition(anchorPose.position); #elif UNITY_WSA || WINDOWS_UWP // Hololens is using SetNativeSpatialAnchorPtr for getting position. localAnchorGameObject.GetComponent <WorldAnchor>().SetNativeSpatialAnchorPtr(foundAnchor.LocalAnchor); #endif }
private void OnCloudAnchorLocated(AnchorLocatedEventArgs args) { Debug.Log("Cloud Anchor Located:" + args.Status); if (args.Status == LocateAnchorStatus.Located) { currentCloudAnchor = args.Anchor; Debug.Log("Anchor ID Found!"); QueueOnUpdate(() => { Pose anchorPose = Pose.identity; #if UNITY_ANDROID || UNITY_IOS anchorPose = currentCloudAnchor.GetAnchorPose(); #endif Debug.Log("Anchor Found!"); Debug.Log("Now setting gameObject to anchor position and rotation."); // HoloLens: The position will be set based on the unityARUserAnchor that was located. #if WINDOWS_UWP || UNITY_WSA //create a local anchor at the location of the object in question gameObject.AddARAnchor(); // 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("Setting Local Anchor to Cloud Anchor Position."); gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(currentCloudAnchor.LocalAnchor); } #else Debug.Log("Cloud anchor position: " + anchorPose.position + ". Cloud Anchor Rotation: " + anchorPose.rotation); SetObjectToAnchorPose(anchorPose.position, anchorPose.rotation); #endif }); } }