void Update()
 {
     m_AnchorSelection.Update();
     if (m_CurrentCursor)
     {
         // Update exposed value
         m_Value.position = m_CurrentCursor.transform.position;
         m_Value.rotation = m_CurrentCursor.transform.rotation;
         if (m_Dragging && !PivotTransform.Similar(Vector3.zero, m_Value.position))
         {
             OnValueUpdate?.Invoke(m_Value);
             m_Dragging = false;
         }
     }
 }
        private void InvokeOnDispatchMarkers(Payload <IViewerAction> viewerAction)
        {
            HasChanged = false;

            lock (m_SyncRoot)
            {
                if (viewerAction.ActionType.RequiresContext(MarkerEditContext.current, viewerAction.Data))
                {
                    viewerAction.ActionType.ApplyPayload(viewerAction.Data, ref m_MarkerEdit, () =>
                    {
                        bool sendUpdate = false;

                        var editedMarker = m_MarkerEdit.ToMarker();
                        // Check if any of the fields are different from controller.
                        if (!PivotTransform.Similar(m_CachedMarker.RelativePosition, editedMarker.RelativePosition) ||
                            !PivotTransform.Similar(m_CachedMarker.RelativeRotationEuler, editedMarker.RelativeRotationEuler) ||
                            !PivotTransform.Similar(m_CachedMarker.ObjectScale, editedMarker.ObjectScale) ||
                            m_CachedMarker.Name != editedMarker.Name)
                        {
                            sendUpdate = true;
                        }

                        // Update drag handle position
                        if (sendUpdate)
                        {
                            m_MarkerController.Visualize(editedMarker);
                            m_UpdateDragHandle.Run(
                                () => m_DraggableMarkerPlacement.UpdatePose(editedMarker.GetWorldPose(m_MarkerController.AlignedObject.Get())),
                                0.1f);
                            m_CachedMarker = editedMarker;
                            m_MarkerEditContextTarget.UpdateWith(ref m_MarkerEdit);
                        }
                        HasChanged = true;
                    });
                }
                if (viewerAction.ActionType.RequiresContext(MarkerListContext.current, viewerAction.Data))
                {
                    viewerAction.ActionType.ApplyPayload(viewerAction.Data, ref m_MarkerList, () =>
                    {
                        m_MarkerListContextTarget.UpdateWith(ref m_MarkerList);
                        HasChanged = true;
                    });
                }
            }
        }
        void OnDragMarkerUpdate(Pose newMarkerPose)
        {
            if (m_MarkerController.AlignedObject == null)
            {
                return;
            }
            var local             = Marker.InverseTransformPose(m_MarkerController.AlignedObject.Transform, newMarkerPose);
            var rotation          = local.rotation.eulerAngles;
            var effectiveRotation = new Vector3(rotation.x, m_MarkerEdit.YAxis, rotation.z);

            // Only update the Y rotation if the marker is on a wall
            // We can determine if on a wall if the X is near zero
            int xmod = Mathf.RoundToInt((rotation.x * 4) / 360) % 4;

            if (xmod == 0)
            {
                effectiveRotation.y = rotation.y;
            }

            // Discard if similar to existing data.
            if (PivotTransform.Similar(local.position, new Vector3(m_MarkerEdit.X, m_MarkerEdit.Y, m_MarkerEdit.Z)) &&
                PivotTransform.Similar(effectiveRotation, new Vector3(m_MarkerEdit.XAxis, m_MarkerEdit.YAxis, m_MarkerEdit.ZAxis)))
            {
                return;
            }

            m_MarkerEdit.X     = local.position.x;
            m_MarkerEdit.Y     = local.position.y;
            m_MarkerEdit.Z     = local.position.z;
            m_MarkerEdit.XAxis = effectiveRotation.x;
            m_MarkerEdit.YAxis = effectiveRotation.y;
            m_MarkerEdit.ZAxis = effectiveRotation.z;
            m_MarkerEditContextTarget.UpdateWith(ref m_MarkerEdit);

            m_MarkerController.Visualize(m_MarkerEdit.ToMarker());
            m_PlaceNewMarker = false;
        }