Ejemplo n.º 1
0
 public virtual void OnDrag(PointerEventData eventData)
 {
     if (eventData.button == PointerEventData.InputButton.Left)
     {
         if (this.IsActive())
         {
             Vector2 a;
             if (RectTransformUtility.ScreenPointToLocalPointInRectangle(this.viewRect, eventData.position, eventData.pressEventCamera, out a))
             {
                 this.UpdateBounds();
                 Vector2 b      = a - this.m_PointerStartLocalCursor;
                 Vector2 vector = this.m_ContentStartPosition + b;
                 Vector2 b2     = this.CalculateOffset(vector - this.m_Content.anchoredPosition);
                 vector += b2;
                 if (this.m_MovementType == ScrollRect.MovementType.Elastic)
                 {
                     if (b2.x != 0f)
                     {
                         vector.x -= ScrollRect.RubberDelta(b2.x, this.m_ViewBounds.size.x);
                     }
                     if (b2.y != 0f)
                     {
                         vector.y -= ScrollRect.RubberDelta(b2.y, this.m_ViewBounds.size.y);
                     }
                 }
                 this.SetContentAnchoredPosition(vector);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///   <para>Handling for when the content is dragged.</para>
        /// </summary>
        /// <param name="eventData"></param>
        public virtual void OnDrag(PointerEventData eventData)
        {
            Vector2 localPoint;

            if (eventData.button != PointerEventData.InputButton.Left || !this.IsActive() || !RectTransformUtility.ScreenPointToLocalPointInRectangle(this.viewRect, eventData.position, eventData.pressEventCamera, out localPoint))
            {
                return;
            }
            this.UpdateBounds();
            Vector2 vector2  = this.m_ContentStartPosition + localPoint - this.m_PointerStartLocalCursor;
            Vector2 offset   = this.CalculateOffset(vector2 - this.m_Content.anchoredPosition);
            Vector2 position = vector2 + offset;

            if (this.m_MovementType == ScrollRect.MovementType.Elastic)
            {
                if ((double)offset.x != 0.0)
                {
                    position.x = position.x - ScrollRect.RubberDelta(offset.x, this.m_ViewBounds.size.x);
                }
                if ((double)offset.y != 0.0)
                {
                    position.y = position.y - ScrollRect.RubberDelta(offset.y, this.m_ViewBounds.size.y);
                }
            }
            this.SetContentAnchoredPosition(position);
        }