/// <summary>
 /// Callback when the set of active spatial anchors changes.
 /// </summary>
 /// <param name="obj">Callback arguments</param>
 /// <remarks>
 /// The only anchor change event we care about is when anchors, which are in the "waitOnLoading" dictionary,
 /// are added. Those are anchors which have been loaded but now need to be finalized.
 /// We ignore other anchor added/changed/removed events.
 /// And in fact, when anchor persistence isn't supported, we don't even bother registering for this event.
 /// </remarks>
 private void OnAnchorsChanged(ARAnchorsChangedEventArgs obj)
 {
     foreach (var added in obj.added)
     {
         DebugLogExtra($"Process Added={added.trackableId}");
         TrackableId trackableId = added.trackableId;
         AnchorId    anchorId;
         if (waitOnLoading.TryGetValue(trackableId, out anchorId))
         {
             Debug.Assert(SpongyAnchors.FindIndex(x => x.anchorId == anchorId) < 0, $"OnAnchorsChanged: {anchorId.FormatStr()} in waiting list, but already in SpongyAnchors");
             added.gameObject.name = anchorId.FormatStr();
             SpongyAnchorARF spongyARF = WrapARAnchor(anchorId, trackableId, added.gameObject);
             // Adding through this path means it was just loaded from anchorStore, which means it's already saved.
             spongyARF.IsSaved = true;
             SpongyAnchors.Add(new SpongyAnchorWithId()
             {
                 anchorId     = anchorId,
                 spongyAnchor = spongyARF
             }
                               );
             waitOnLoading.Remove(trackableId);
         }
         else
         {
             DebugLogExtra($"Incoming trackableId={trackableId} but not in waiting list of {waitOnLoading.Count} pending anchors");
         }
     }
 }
Esempio n. 2
0
 void OnAnchorsChanged(ARAnchorsChangedEventArgs args)
 {
     if (args.updated.Contains(Anchor))
     {
         Moved?.Invoke(Pose);
     }
 }
 private void OnAnchorsChanged(ARAnchorsChangedEventArgs eventArgs)
 {
     if (eventArgs.added.Count > 0)
     {
         Transform targetTransform = eventArgs.added.Last().transform;
         Pose      targetPose      = new Pose(targetTransform.position, targetTransform.rotation);
         MoveTrackingObj(targetPose);
     }
 }
Esempio n. 4
0
    void OnAnchorsChanged(ARAnchorsChangedEventArgs eventArgs)
    {
        foreach (var anchor in eventArgs.added)
        {
            UpdateAnchor(anchor);
        }

        foreach (var anchor in eventArgs.updated)
        {
            UpdateAnchor(anchor);
        }
    }
    void OnAnchorsChanged(ARAnchorsChangedEventArgs eventArgs)
    {
        foreach (var referencePoint in eventArgs.added)
        {
            UpdateAnchor(referencePoint);
        }

        foreach (var referencePoint in eventArgs.updated)
        {
            UpdateAnchor(referencePoint);
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Called when anchors of the ARAnchorManager are changed (not tracking, tracking, added, etc.)
    /// </summary>
    /// <param name="obj"></param>
    private void OnAnchorsChanged(ARAnchorsChangedEventArgs obj)
    {
        // TODO: check if it is working for cloud anchors
        if (CalibrationManager.Instance.Calibrated)
        {
            if (!CalibrationManager.Instance.UsingCloudAnchors)
            {
                //if (obj.updated[obj.updated.IndexOf(CalibrationManager.Instance.WorldAnchorLocal)].trackingState == TrackingState.Tracking) {
                switch (CalibrationManager.Instance.WorldAnchorLocal.trackingState)
                {
                case TrackingState.Tracking:
                    if (anchorTrackingStatus != AnchorTrackingStatus.Tracking)
                    {
                        // cancel previously invoked tracking failure notification
                        StopTrackingFailureNotifications();
                        StopTrackingFailureTimeout();

                        anchorTrackingStatus = AnchorTrackingStatus.Tracking;
                        if (deviceTrackingStatus == DeviceTrackingStatus.WaitingForAnchor)
                        {
                            Notifications.Instance.ShowNotification("Tracking state", "Session Tracking");
                            GameManager.Instance.SceneSetActive(true);
                            deviceTrackingStatus = DeviceTrackingStatus.Tracking;
                            StopTrackingFailureNotifications(stopVideoOverride: true);
                        }
                    }
                    break;

                case TrackingState.Limited:
                case TrackingState.None:
                    // cancel previously invoked tracking failure notification
                    StopTrackingFailureNotifications();

                    trackingAnchorFailureNotify = StartCoroutine(TrackingFailureNotify("Tracking lost!", "Look around your workspace.", 9f, anchorTrackingFailure: true));
                    TrackingLostAnimation.PlayVideo();
                    anchorTrackingStatus = AnchorTrackingStatus.NotTracking;
                    GameManager.Instance.SceneSetActive(false);
                    if (trackingAnchorFailureTimeout == null)
                    {
                        trackingAnchorFailureTimeout = StartCoroutine(TrackingFailureTimeout(AnchorTrackingLostTimeout));
                    }
                    break;
                }
            }
        }
        else
        {
            anchorTrackingStatus = AnchorTrackingStatus.NotCalibrated;
        }
    }
        private void AnchorsChanged(ARAnchorsChangedEventArgs eventArgs)
        {
            foreach (var added in eventArgs.added)
            {
                // Keep any anchors created by this scene contained within the scene, for multi-scene management.
                added.transform.SetParent(m_anchorsContainer.transform, worldPositionStays: true);

#if !AR_FOUNDATION_4_1_1_OR_LATER
                // TryAddAnchor returns the anchor upon success, but it must also be reported in the next
                // AnchorsChanged update. These double adds are ignored, but other added anchors are processed.
                if (m_anchors.Contains(added))
                {
                    continue;
                }
#endif
                Debug.Log($"Anchor added from ARAnchorsChangedEvent: {added.trackableId}, OpenXR Handle: {added.GetOpenXRHandle()}");
                m_anchors.Add(added);

                // If this anchor being added was requested from the anchor store, it is recognized here
                if (m_incomingPersistedAnchors.TryGetValue(added.trackableId, out string name))
                {
                    if (added.TryGetComponent(out SampleAnchor sampleAnchor))
                    {
                        sampleAnchor.Name          = name;
                        sampleAnchor.Persisted     = true;
                        sampleAnchor.TrackingState = added.trackingState;
                    }
                    m_incomingPersistedAnchors.Remove(added.trackableId);
                }
            }

            foreach (ARAnchor updated in eventArgs.updated)
            {
                if (updated.TryGetComponent(out SampleAnchor sampleAnchor))
                {
                    sampleAnchor.TrackingState = updated.trackingState;
                }
            }

            foreach (var removed in eventArgs.removed)
            {
                Debug.Log($"Anchor removed: {removed.trackableId}");
                m_anchors.Remove(removed);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Keeps track of when platform anchors (surfaced by ARFoundation as ARAnchors) are
        /// added/updated/removed by ARFoundation.  This is critical for mapping Azure Spatial Anchors CloudAnchors
        /// to Unity ARFoundation Reference Points.
        /// </summary>
        /// <param name="obj">Event args with information about what has changed.</param>
        private void ARAnchorManager_AnchorsChanged(ARAnchorsChangedEventArgs obj)
        {
            lock (pointerToAnchors)
            {
                foreach (ARAnchor aRAnchor in obj.added)
                {
                    string lookupkey = aRAnchor.nativePtr.GetPlatformPointer().GetPlatformKey();
                    if (!pointerToAnchors.ContainsKey(lookupkey))
                    {
                        pointerToAnchors.Add(lookupkey, aRAnchor);
                    }
                }

                foreach (ARAnchor aRAnchor in obj.removed)
                {
                    string toremove = null;
                    foreach (var kvp in pointerToAnchors)
                    {
                        if (kvp.Value == aRAnchor)
                        {
                            toremove = kvp.Key;
                            break;
                        }
                    }

                    if (toremove != null)
                    {
                        pointerToAnchors.Remove(toremove);
                    }
                }

                foreach (ARAnchor aRAnchor in obj.updated)
                {
                    string lookupKey = aRAnchor.nativePtr.GetPlatformPointer().GetPlatformKey();
                    if (!pointerToAnchors.ContainsKey(lookupKey))
                    {
                        pointerToAnchors.Add(lookupKey, aRAnchor);
                    }
                }
            }
        }