示例#1
0
        private void UpdateCache()
        {
            if (thisRectTransform != null)
            {
                thisRectTransform.GetWorldCorners(corners);
                rect.Set(corners[1].x, corners[1].y, Mathf.Abs(corners[2].x - corners[1].x),
                         Mathf.Abs(corners[0].y - corners[1].y));
                center.Set((corners[2].x + corners[1].x) / 2.0f, (corners[1].y + corners[0].y) / 2.0f, corners[0].z);
            }

            if (thisTransform.childCount != childCount)
            {
                contentChilds.Clear();
                for (int i = 0; i < thisTransform.childCount; i++)
                {
                    contentChilds.Add(new ScrollViewItem(thisTransform.GetChild(i)));

                    if (i == 0)
                    {
                        closestChild = contentChilds[i];
                    }
                }

                Reposition();

                childCount = thisTransform.childCount;
            }
        }
示例#2
0
        protected virtual void SetContentAnchoredPosition(Vector2 deltaPosition, Vector2 moveDelta)
        {
            for (int i = 0; i < contentChilds.Count; i++)
            {
                if (Direction != CircularScrollViewDirection.Horizontal)
                {
                    deltaPosition.x = 0;
                }

                if (Direction != CircularScrollViewDirection.Vertical)
                {
                    deltaPosition.y = 0;
                }

                if (deltaPosition != contentChilds[i].RectTransform.anchoredPosition)
                {
                    contentChilds[i].RectTransform.anchoredPosition += deltaPosition;
                }

                contentChilds[i].UpdateDistance(center, Direction);

                ScrollViewItem aux = null;

                if (closestChild == null)
                {
                    aux          = closestChild;
                    closestChild = contentChilds[i];
                    onChange(closestChild.GameObject, aux != null ? aux.GameObject : null);
                }
                else
                {
                    if (Mathf.Abs(contentChilds[i].DistanceFromCenter) < Mathf.Abs(closestChild.DistanceFromCenter))
                    {
                        aux          = closestChild;
                        closestChild = contentChilds[i];
                        onChange(closestChild.GameObject, aux != null ? aux.GameObject : null);
                    }
                }
            }
        }
示例#3
0
        private void MoveAllInvisibleTo(bool toStart)
        {
            if (contentChilds.TrueForAll(item => item.IsVisible == false))
            {
                return;
            }

            if (contentChilds.Count > 0)
            {
                ScrollViewItem target      = toStart ? contentChilds.Last() : contentChilds.FirstOrDefault();
                ScrollViewItem destination = toStart ? contentChilds.FirstOrDefault() : contentChilds.Last();

                while (!target.IsVisible)
                {
                    if (toStart)
                    {
                        target.Transform.SetAsFirstSibling();
                    }
                    else
                    {
                        target.Transform.SetAsLastSibling();
                    }

                    if (Direction == CircularScrollViewDirection.Horizontal)
                    {
                        target.RectTransform.anchoredPosition = new Vector2(
                            toStart
                                ? destination.RectTransform.anchoredPosition.x - destination.RectTransform.rect.width -
                            Spacing
                                : destination.RectTransform.anchoredPosition.x + destination.RectTransform.rect.width +
                            Spacing,
                            destination.RectTransform.anchoredPosition.y);
                    }

                    if (Direction == CircularScrollViewDirection.Vertical)
                    {
                        target.RectTransform.anchoredPosition = new Vector2(
                            destination.RectTransform.anchoredPosition.x,
                            toStart
                                ? destination.RectTransform.anchoredPosition.y - destination.RectTransform.rect.height -
                            Spacing
                                : destination.RectTransform.anchoredPosition.y + destination.RectTransform.rect.height +
                            Spacing);
                    }

                    target.UpdateVisibility(rect);
                    target.UpdateDistance(center, Direction);

                    if (toStart)
                    {
                        contentChilds.MoveBackwards();
                    }
                    else
                    {
                        contentChilds.MoveForward();
                    }

                    target      = toStart ? contentChilds.Last() : contentChilds.FirstOrDefault();
                    destination = toStart ? contentChilds.FirstOrDefault() : contentChilds.Last();
                }
            }
        }