public GizmoHandleHoverData GetGizmoHandleHoverData(Gizmo gizmo)
        {
            Camera focusCamera         = gizmo.FocusCamera;
            Ray    hoverRay            = RTInputDevice.Get.Device.GetRay(focusCamera);
            var    hoverDataCollection = gizmo.GetAllHandlesHoverData(hoverRay);

            Vector3 screenRayOrigin = focusCamera.WorldToScreenPoint(hoverRay.origin);

            hoverDataCollection.Sort(delegate(GizmoHandleHoverData h0, GizmoHandleHoverData h1)
            {
                var handle0 = gizmo.GetHandleById_SystemCall(h0.HandleId);
                var handle1 = gizmo.GetHandleById_SystemCall(h1.HandleId);

                // Same dimensions?
                bool sameDims = (h0.HandleDimension == h1.HandleDimension);
                if (sameDims)
                {
                    // 2D dimension?
                    if (h0.HandleDimension == GizmoDimension.Dim2D)
                    {
                        // If the priorities are equal, we sort by distance from screen ray origin.
                        // Otherwise, we sort by priority.
                        if (handle0.HoverPriority2D == handle1.HoverPriority2D)
                        {
                            float d0 = (screenRayOrigin - h0.HoverPoint).sqrMagnitude;
                            float d1 = (screenRayOrigin - h1.HoverPoint).sqrMagnitude;
                            return(d0.CompareTo(d1));
                        }
                        else
                        {
                            return(handle0.HoverPriority2D.CompareTo(handle1.HoverPriority2D));
                        }
                    }
                    // 3D dimension
                    else
                    {
                        // If the priorities are equal, we sort by hover enter. Otherwise, we sort by priority.
                        if (handle0.HoverPriority3D == handle1.HoverPriority3D)
                        {
                            return(h0.HoverEnter3D.CompareTo(h1.HoverEnter3D));
                        }
                        else
                        {
                            return(handle0.HoverPriority3D.CompareTo(handle1.HoverPriority3D));
                        }
                    }
                }
                else
                {
                    // When the dimensions differ, we will sort by the gizmo generic priority. If the priorities are equal,
                    // we will give priority to 2D handles.
                    if (handle0.GenericHoverPriority == handle1.GenericHoverPriority)
                    {
                        if (h0.HandleDimension == GizmoDimension.Dim2D)
                        {
                            return(-1);
                        }
                        return(1);
                    }
                    return(handle0.GenericHoverPriority.CompareTo(handle1.GenericHoverPriority));
                }
            });

            return(hoverDataCollection.Count != 0 ? hoverDataCollection[0] : null);
        }