Search Unity

Why ScrollRect delta doesn't change when I modified normalizedPosition?

Discussion in 'UGUI & TextMesh Pro' started by EAST-DATA, Aug 7, 2015.

  1. EAST-DATA

    EAST-DATA

    Joined:
    Oct 29, 2013
    Posts:
    7
    Hi there,
    I changed normalizedPosition value by code when I'm dragging scrollrect (not release finger), but scroll delta doesn't change, so scrollview come back to before normalizedPosition changed when I keep dragging (still not release finger). Someone help.
     
  2. Dreams

    Dreams

    Joined:
    Sep 9, 2011
    Posts:
    22
    ScrollRect uses current mouse position - start mouse position to update/calculate normalizedposition (instead of for instance using delta or otherwise handling any updates to normalizedposition).
    The source for ScrollRect in 5.1 is here:
    https://bitbucket.org/Unity-Technol...8/UnityEngine.UI/UI/Core/ScrollRect.cs?at=5.1

    I have the same problem and thinking about overriding the OnDrag function where it calculates the delta (line 256 -
    var pointerDelta = localCursor - m_PointerStartLocalCursor;
    ) to use eventData.delta instead. But havent tried if it would work as expected yet.
     
  3. EAST-DATA

    EAST-DATA

    Joined:
    Oct 29, 2013
    Posts:
    7
    It worked, Thanks a lot!!!
    Code (CSharp):
    1. public class Scroller : ScrollRect
    2. {
    3.     PointerEventData m_beginEventData;
    4.     public override void OnBeginDrag(PointerEventData eventData)
    5.     {
    6.         base.OnBeginDrag(eventData);
    7.         m_beginEventData = eventData;
    8.     }
    9.     public void Reset()
    10.     {
    11.         OnBeginDrag(m_beginEventData);
    12.     }
    13. }
    Reset() after modified normalizedposition.