/// <summary> /// Destroying the attached Behaviour will result in the game or Scene /// receiving OnDestroy. /// </summary> private void OnDestroy() { if (this.WorldAnchor != null) { #if UNITY_2019_3_OR_NEWER SpatialAnchorManager.arAnchorManager.RemoveAnchor(this.WorldAnchor); #else SpatialAnchorManager.arAnchorManager.RemoveReferencePoint(this.WorldAnchor); #endif this.WorldAnchor = null; } }
bool TryRemoveReferencePointInternal(TrackableId referencePointId, ARReferencePoint referencePoint) { var referencePointSubsystem = ARSubsystemManager.referencePointSubsystem; if (!referencePointSubsystem.TryRemoveReferencePoint(referencePointId)) { return(false); } Destroy(referencePoint.gameObject); m_ReferencePoints.Remove(referencePointId); return(true); }
/// <summary> /// Constructor invoked by the <see cref="ARReferencePointManager"/> which triggered this event. /// </summary> /// <param name="referencePoint">The reference point component that was updated.</param> /// <param name="previousTrackingState">The tracking state prior to this update.</param> /// <param name="previousPose">The session-space pose prior to this update.</param> public ARReferencePointUpdatedEventArgs( ARReferencePoint referencePoint, TrackingState previousTrackingState, Pose previousPose) { if (referencePoint == null) { throw new ArgumentNullException("referencePoint"); } this.referencePoint = referencePoint; this.previousTrackingState = previousTrackingState; previousSessionRelativePose = previousPose; }
void OnReferencePointUpdated(ReferencePointUpdatedEventArgs eventArgs) { var referencePointData = eventArgs.ReferencePoint; ARReferencePoint referencePoint = TryGetReferencePoint(referencePointData.Id); if (referencePoint == null) { referencePoint = CreateArReferencePoint(eventArgs.ReferencePoint); } referencePoint.sessionRelativeData = referencePointData; // Notify event subscribers RaiseReferencePointUpdatedEvent(eventArgs, referencePoint); }
void OnReferencePointUpdated(ReferencePointUpdatedEventArgs eventArgs) { var referencePointData = eventArgs.ReferencePoint; ARReferencePoint referencePoint = TryGetReferencePoint(referencePointData.Id); if (referencePoint == null) { // We aren't responsible for this reference point, so ignore it. return; } referencePoint.sessionRelativeData = referencePointData; // Notify event subscribers RaiseReferencePointUpdatedEvent(eventArgs, referencePoint); }
/// <summary> /// Attempts to remove an <see cref="ARReferencePoint"/>. /// </summary> /// <param name="referencePoint">The reference point you wish to remove.</param> /// <returns>True if the reference point was successfully removed. /// False usually means the reference point doesn't exist or isn't tracked by this manager.</returns> public bool TryRemoveReferencePoint(ARReferencePoint referencePoint) { if (referencePoint == null) { return(false); } TrackableId referencePointId = referencePoint.sessionRelativeData.Id; if (!m_ReferencePoints.ContainsKey(referencePointId)) { return(false); } return(TryRemoveReferencePointInternal(referencePointId, referencePoint)); }
/// <summary> /// Gets an anchor <see cref="Pose"/> from the specified native anchor <see cref="IntPtr"/>. /// </summary> /// <param name="anchorPointer">The anchor pointer.</param> /// <returns><see cref="Pose"/>.</returns> /// <exception cref="System.InvalidOperationException">Invalid anchor pointer. Can't get the pose.</exception> private static Pose GetPose(IntPtr anchorPointer) { if (anchorPointer == IntPtr.Zero) { throw new InvalidOperationException("Invalid anchor pointer. Can't get the pose."); } ARAnchor anchor = SpatialAnchorManager.AnchorFromPointer(anchorPointer); if (anchor == null) { Debug.Log("Didn't find the anchor"); return(Pose.identity); } return(new Pose(anchor.transform.position, anchor.transform.rotation)); }
/// <summary> /// Creates an <see cref="ARAnchor"/> from the specified <see cref="Transform"/>. /// </summary> /// <param name="position">The position.</param> /// <param name="rotation">The rotation.</param> /// <returns>An AR Foundation <see cref="ARAnchor"/>.</returns> /// <exception cref="InvalidOperationException">Unable to create an anchor.</exception> public static ARAnchor CreateAnchor(Vector3 position, Quaternion rotation) { Pose anchorPose = new Pose(position, rotation); #if UNITY_2019_3_OR_NEWER ARAnchor anchor = SpatialAnchorManager.arAnchorManager.AddAnchor(anchorPose); #else ARAnchor anchor = SpatialAnchorManager.arAnchorManager.AddReferencePoint(anchorPose); #endif if (anchor == null) { Debug.LogError("Unable to create an anchor."); throw new InvalidOperationException("Unable to create an anchor."); } return(anchor); }
/// <summary> /// Gets a <see cref="Pose"/> from the specified <see cref="ARAnchor"/>. /// </summary> /// <param name="anchor">The anchor.</param> /// <returns><see cref="Pose"/>.</returns> public static Pose GetPose(ARAnchor anchor) { return(new Pose(anchor.transform.position, anchor.transform.rotation)); }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> private void Awake() { this.WorldAnchor = AnchorHelpers.CreateWorldAnchor(this.gameObject.transform); this.gameObject.transform.SetParent(this.WorldAnchor.transform, true); }
void RaiseReferencePointUpdatedEvent(ReferencePointUpdatedEventArgs eventArgs, ARReferencePoint referencePoint) { if (referencePointUpdated == null) { return; } referencePointUpdated(new ARReferencePointUpdatedEventArgs( referencePoint, eventArgs.PreviousTrackingState, eventArgs.PreviousPose)); }