// Update the scroll bar's position based on the mouse. void UpdateDrag(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } if (m_ContainerRect == null) { return; } Vector2 position = Vector2.zero; if (!MultipleDisplayUtilities.GetRelativeMousePositionForDrag(eventData, ref position)) { return; } Vector2 localCursor; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(m_ContainerRect, position, eventData.pressEventCamera, out localCursor)) { return; } Vector2 handleCenterRelativeToContainerCorner = localCursor - m_Offset - m_ContainerRect.rect.position; Vector2 handleCorner = handleCenterRelativeToContainerCorner - (m_HandleRect.rect.size - m_HandleRect.sizeDelta) * 0.5f; float parentSize = axis == 0 ? m_ContainerRect.rect.width : m_ContainerRect.rect.height; float remainingSize = parentSize * (1 - size); if (remainingSize <= 0) { return; } DoUpdateDrag(handleCorner, remainingSize); }
// Update the slider's position based on the mouse. void UpdateDrag(PointerEventData eventData, Camera cam) { RectTransform clickRect = m_HandleContainerRect ?? m_FillContainerRect; if (clickRect != null && clickRect.rect.size[(int)axis] > 0) { Vector2 position = Vector2.zero; if (!MultipleDisplayUtilities.GetRelativeMousePositionForDrag(eventData, ref position)) { return; } Vector2 localCursor; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, position, cam, out localCursor)) { return; } localCursor -= clickRect.rect.position; float val = Mathf.Clamp01((localCursor - m_Offset)[(int)axis] / clickRect.rect.size[(int)axis]); normalizedValue = (reverseValue ? 1f - val : val); } }