Beispiel #1
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 == CHScrollRect.MovementType.Elastic)
            {
                if ((double)offset.x != 0.0)
                {
                    position.x = position.x - CHScrollRect.RubberDelta(offset.x, this.m_ViewBounds.size.x);
                }
                if ((double)offset.y != 0.0)
                {
                    position.y = position.y - CHScrollRect.RubberDelta(offset.y, this.m_ViewBounds.size.y);
                }
            }
            this.SetContentAnchoredPosition(position);
        }
Beispiel #2
0
        private Bounds GetBounds()
        {
            if ((UnityEngine.Object) this.m_Content == (UnityEngine.Object)null)
            {
                return(new Bounds());
            }
            this.m_Content.GetWorldCorners(this.m_Corners);
            Matrix4x4 worldToLocalMatrix = this.viewRect.worldToLocalMatrix;

            return(CHScrollRect.InternalGetBounds(this.m_Corners, ref worldToLocalMatrix));
        }
Beispiel #3
0
        /// <summary>
        ///   <para>Calculate the bounds the ScrollRect should be using.</para>
        /// </summary>
        protected void UpdateBounds()
        {
            this.m_ViewBounds    = new Bounds((Vector3)this.viewRect.rect.center, (Vector3)this.viewRect.rect.size);
            this.m_ContentBounds = this.GetBounds();
            if ((UnityEngine.Object) this.m_Content == (UnityEngine.Object)null)
            {
                return;
            }
            Vector3 size   = this.m_ContentBounds.size;
            Vector3 center = this.m_ContentBounds.center;
            Vector2 pivot  = this.m_Content.pivot;

            CHScrollRect.AdjustBounds(ref this.m_ViewBounds, ref pivot, ref size, ref center);
            this.m_ContentBounds.size   = size;
            this.m_ContentBounds.center = center;
            if (this.movementType != CHScrollRect.MovementType.Clamped)
            {
                return;
            }
            Vector2 zero = Vector2.zero;

            if ((double)this.m_ViewBounds.max.x > (double)this.m_ContentBounds.max.x)
            {
                zero.x = Math.Min(this.m_ViewBounds.min.x - this.m_ContentBounds.min.x, this.m_ViewBounds.max.x - this.m_ContentBounds.max.x);
            }
            else if ((double)this.m_ViewBounds.min.x < (double)this.m_ContentBounds.min.x)
            {
                zero.x = Math.Max(this.m_ViewBounds.min.x - this.m_ContentBounds.min.x, this.m_ViewBounds.max.x - this.m_ContentBounds.max.x);
            }
            if ((double)this.m_ViewBounds.min.y < (double)this.m_ContentBounds.min.y)
            {
                zero.y = Math.Max(this.m_ViewBounds.min.y - this.m_ContentBounds.min.y, this.m_ViewBounds.max.y - this.m_ContentBounds.max.y);
            }
            else if ((double)this.m_ViewBounds.max.y > (double)this.m_ContentBounds.max.y)
            {
                zero.y = Math.Min(this.m_ViewBounds.min.y - this.m_ContentBounds.min.y, this.m_ViewBounds.max.y - this.m_ContentBounds.max.y);
            }
            if ((double)zero.sqrMagnitude > 1.40129846432482E-45)
            {
                Vector3 contentPos = (Vector3)(this.m_Content.anchoredPosition + zero);
                if (!this.m_Horizontal)
                {
                    contentPos.x = this.m_Content.anchoredPosition.x;
                }
                if (!this.m_Vertical)
                {
                    contentPos.y = this.m_Content.anchoredPosition.y;
                }
                CHScrollRect.AdjustBounds(ref this.m_ViewBounds, ref pivot, ref size, ref contentPos);
            }
        }
Beispiel #4
0
 public void Awake()
 {
     _scrollRect = GetComponent <CHScrollRect>();
     if (!_scrollingPanel)
     {
         _scrollingPanel = _scrollRect.content;
     }
     if (!_center)
     {
         Debug.LogError("Please define the RectTransform for the Center viewport of the scrollable area");
     }
     if (_arrayOfElements == null || _arrayOfElements.Length == 0)
     {
         var childCount = _scrollRect.content.childCount;
         if (childCount > 0)
         {
             _arrayOfElements = new GameObject[childCount];
             for (int i = 0; i < childCount; i++)
             {
                 _arrayOfElements[i] = _scrollRect.content.GetChild(i).gameObject;
             }
         }
     }
 }
Beispiel #5
0
 private void UpdateScrollbarVisibility()
 {
     CHScrollRect.UpdateOneScrollbarVisibility(this.vScrollingNeeded, this.m_Vertical, this.m_VerticalScrollbarVisibility, this.m_VerticalScrollbar);
     CHScrollRect.UpdateOneScrollbarVisibility(this.hScrollingNeeded, this.m_Horizontal, this.m_HorizontalScrollbarVisibility, this.m_HorizontalScrollbar);
 }
Beispiel #6
0
 private Vector2 CalculateOffset(Vector2 delta)
 {
     return(CHScrollRect.InternalCalculateOffset(ref this.m_ViewBounds, ref this.m_ContentBounds, this.m_Horizontal, this.m_Vertical, this.m_MovementType, ref delta));
 }