Exemple #1
0
    void OnReferencePointsChanged(ARReferencePointsChangedEventArgs eventArgs)
    {
        foreach (var referencePoint in eventArgs.added)
        {
            UpdateReferencePoint(referencePoint);
        }

        foreach (var referencePoint in eventArgs.updated)
        {
            UpdateReferencePoint(referencePoint);
        }
    }
        /// <summary>
        /// Keeps track of when platform anchors (surfaced by ARFoundation as ARReferencePoints) 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 ARReferencePointManager_referencePointsChanged(ARReferencePointsChangedEventArgs obj)
        {
            lock (pointerToReferencePoints)
            {
                foreach (ARReferencePoint aRReferencePoint in obj.added)
                {
                    string lookupkey = aRReferencePoint.nativePtr.GetPlatformPointer().GetPlatformKey();
                    if (!pointerToReferencePoints.ContainsKey(lookupkey))
                    {
                        pointerToReferencePoints.Add(lookupkey, aRReferencePoint);
                    }
                }

                foreach (ARReferencePoint aRReferencePoint in obj.removed)
                {
                    string toremove = null;
                    foreach (var kvp in pointerToReferencePoints)
                    {
                        if (kvp.Value == aRReferencePoint)
                        {
                            toremove = kvp.Key;
                            break;
                        }
                    }

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

                foreach (ARReferencePoint aRReferencePoint in obj.updated)
                {
                    string lookupKey = aRReferencePoint.nativePtr.GetPlatformPointer().GetPlatformKey();
                    if (!pointerToReferencePoints.ContainsKey(lookupKey))
                    {
                        pointerToReferencePoints.Add(lookupKey, aRReferencePoint);
                    }
                }
            }
        }