예제 #1
0
        protected override ScrollElement RemoveElementFromShoing(int Idx)
        {
            ScrollElement removedElement = m_ShowingElements[Idx];

            m_ShowingElements.RemoveAt(Idx);
            return(removedElement);
        }
예제 #2
0
        protected override int GetCenterNearlyElement()
        {
            float         centerPos    = CountCeneterPos();
            ScrollElement element      = m_ShowingElements[0];
            int           midleIdx     = 0;
            float         startPos     = element.rect.localPosition.x;
            float         elementWidth = m_SampleElement.rect.width;
            float         elementSpace = elementWidth + m_SpaceBTElements;

            float lastDst = 999999999999999999;

            for (int idx = 0; idx < m_ShowingElements.Count; ++idx)
            {
                float elementCeneter = startPos + elementWidth / 2;
                float countDst       = Mathf.Abs(centerPos - elementCeneter);

                if (countDst < lastDst)
                {
                    lastDst   = countDst;
                    midleIdx  = idx;
                    startPos += elementSpace;
                }
                else
                {
                    break;
                }
            }
            return(midleIdx);
        }
예제 #3
0
        public override void Reset()
        {
            base.Reset();
            Vector2 size      = m_ElementContainer.sizeDelta;
            Vector2 countSize = (Vector2)(elementEndShift * m_ElementsInfoAgent.GetInfoCount() - elementLineDirector * m_SpaceBTElements);

            size.x = Mathf.Abs(countSize.x) > 0 ? Mathf.Abs(countSize.x) : size.x;
            size.y = Mathf.Abs(countSize.y) > 0 ? Mathf.Abs(countSize.y) : size.y;
            Vector2 elementdir = elementLineDirector;

            elementdir.x = Mathf.Abs(elementdir.x);
            elementdir.y = Mathf.Abs(elementdir.y);
            size        += elementdir * (m_HeadSpace + m_TailSpace);
            m_ElementContainer.sizeDelta = size;
            IEnumerator <ScrollElement> chipsEnumerator = m_ShowingElements.GetEnumerator();

            chipsEnumerator.Reset();
            while (chipsEnumerator.MoveNext())
            {
                DisPawnElement(chipsEnumerator.Current);
            }
            m_ShowingElements.Clear();
            int headIdx = CountHeadIdx();

            if (headIdx < m_ElementsInfoAgent.GetInfoCount() - 1)
            {
                ScrollElement headElement = SpawnElement();
                AddHead(headElement);
            }
        }
예제 #4
0
        protected override bool IsOutTailBounce()
        {
            ScrollElement tailElement = m_ShowingElements[showingElementsNum - 1];

            CountItemAnchorsPosOnContentPositon(m_ItemAchorsInContentPos, tailElement.rect);
            if (m_ViewAnchorsInContentPos[2].x < m_ItemAchorsInContentPos[0].x)
            {
                return(true);
            }
            return(false);
        }
예제 #5
0
        protected override bool IsOutHeadBounce()
        {
            ScrollElement headElement = m_ShowingElements[0];

            CountItemAnchorsPosOnContentPositon(m_ItemAchorsInContentPos, headElement.rect);
            if (m_ViewAnchorsInContentPos[0].x > m_ItemAchorsInContentPos[2].x)
            {
                return(true);
            }
            return(false);
        }
예제 #6
0
        protected override void AddTail(ScrollElement tailElement)
        {
            ScrollElement perTailEleemnt = m_ShowingElements[showingElementsNum - 1];
            Vector2       anchorPositon  = perTailEleemnt.rect.anchoredPosition;

            anchorPositon += elementEndShift;
            tailElement.rect.anchoredPosition = anchorPositon;

            tailElement = InitScrollElement(tailElement, perTailEleemnt.idx + 1);
            m_ShowingElements.Add(tailElement);
        }
예제 #7
0
        protected override void AddTail(ScrollElement tailElement)
        {
            ScrollElement perTailEleemnt = m_ShowingElements[showingElementsNum - 1];

            tailElement = InitScrollElement(tailElement, perTailEleemnt.idx + 1);

            Vector3 anchorPositon = perTailEleemnt.rect.anchoredPosition;

            anchorPositon.x += m_SampleElement.rect.width + m_SpaceBTElements;
            tailElement.rect.anchoredPosition = anchorPositon;
            m_ShowingElements.Add(tailElement);
        }
예제 #8
0
        protected override void Bounce()
        {
            float centerPos = CountCeneterPos();

            ScrollElement element   = m_ShowingElements[GetCenterNearlyElement()];
            float         dist      = centerPos - m_SampleElement.rect.width / 2 - element.rect.localPosition.x;
            Vector3       targetPos = m_ElementContainer.localPosition;

            targetPos.x += dist;
            Vector3 finalyPos = new Vector3();

            finalyPos = Vector3.SmoothDamp(m_ElementContainer.localPosition, targetPos, ref bounceSpeed, m_BounceBackTime);
            m_ElementContainer.localPosition = finalyPos;
        }
예제 #9
0
        protected override bool IsOutTailBounce()
        {
            ScrollElement tailElement = m_ShowingElements[showingElementsNum - 1];
            Vector2       viewHeadPos = CountHeadPosOfView();
            Vector2       viewTailPos = CountTailPosOfView();

            Vector2 viewVector    = viewTailPos - viewHeadPos;
            Vector2 elementVector = viewTailPos - tailElement.rect.anchoredPosition;

            if (Vector2.Dot(viewVector, elementVector) < 0)
            {
                return(true);
            }
            return(false);
        }
예제 #10
0
        protected override bool IsOutHeadBounce()
        {
            ScrollElement headElement = m_ShowingElements[0];
            Vector2       viewHeadPos = CountHeadPosOfView();
            Vector2       viewTailPos = CountTailPosOfView();

            Vector2 viewVector    = viewTailPos - viewHeadPos;
            Vector2 elementVector = viewHeadPos - headElement.rect.anchoredPosition - elementTailShift;

            if (Vector2.Dot(viewVector, elementVector) > 0)
            {
                return(true);
            }
            return(false);
        }
예제 #11
0
        protected override bool IsNeedAddTail()
        {
            ScrollElement tailElement = m_ShowingElements[showingElementsNum - 1];

            if (tailElement.idx >= m_ElementsAgent.GetInfoCount() - 1)
            {
                return(false);
            }
            CountItemAnchorsPosOnContentPositon(m_ItemAchorsInContentPos, tailElement.rect);
            if (m_ViewAnchorsInContentPos[2].x > m_ItemAchorsInContentPos[2].x)
            {
                return(true);
            }
            return(false);
        }
예제 #12
0
        protected override bool IsNeedAddHead()
        {
            if (showingElementsNum <= 0)
            {
                return(true);
            }
            ScrollElement headElement = m_ShowingElements[0];

            if (headElement.idx <= 0)
            {
                return(false);
            }
            CountItemAnchorsPosOnContentPositon(m_ItemAchorsInContentPos, headElement.rect);
            if (m_ViewAnchorsInContentPos[0].x < m_ItemAchorsInContentPos[0].x)
            {
                return(true);
            }
            return(false);
        }
예제 #13
0
        protected override bool IsNeedAddTail()
        {
            ScrollElement tailElement = m_ShowingElements[showingElementsNum - 1];

            if (tailElement.idx >= m_ElementsInfoAgent.GetInfoCount() - 1)
            {
                return(false);
            }
            Vector2 viewHeadPos = CountHeadPosOfView();
            Vector2 viewTailPos = CountTailPosOfView();

            Vector2 viewVector    = viewTailPos - viewHeadPos;
            Vector2 elementVector = viewTailPos - tailElement.rect.anchoredPosition - elementTailShift;

            if (Vector2.Dot(viewVector, elementVector) > 0)
            {
                return(true);
            }
            return(false);
        }
예제 #14
0
        protected override void AddHead(ScrollElement headElement)
        {
            if (showingElementsNum > 0)
            {
                ScrollElement perHeadEleemnt = m_ShowingElements[0];
                headElement = InitScrollElement(headElement, perHeadEleemnt.idx - 1);

                Vector2 anchorPositon = perHeadEleemnt.rect.anchoredPosition;
                anchorPositon -= elementEndShift;
                headElement.rect.anchoredPosition = anchorPositon;
                m_ShowingElements.Insert(0, headElement);
            }
            else
            {
                int headIdx = CountHeadIdx();
                headElement = InitScrollElement(headElement, headIdx);
                Vector2 newPosition = CountPosByIdx(headIdx);
                headElement.rect.anchoredPosition = newPosition;
                m_ShowingElements.Insert(0, headElement);
            }
        }
예제 #15
0
        protected override void AddHead(ScrollElement headElement)
        {
            if (showingElementsNum > 0)
            {
                ScrollElement perHeadEleemnt = m_ShowingElements[0];
                headElement = InitScrollElement(headElement, perHeadEleemnt.idx - 1);

                Vector3 anchorPositon = perHeadEleemnt.rect.anchoredPosition;
                anchorPositon.x -= m_SampleElement.rect.width + m_SpaceBTElements;
                headElement.rect.anchoredPosition = anchorPositon;
                m_ShowingElements.Insert(0, headElement);
            }
            else
            {
                int headIdx = CountHeadIdx();
                headElement = InitScrollElement(headElement, headIdx);
                Vector3 newPosition = headElement.rect.anchoredPosition;
                newPosition.x = CountPosByIdx(headIdx);
                headElement.rect.anchoredPosition = newPosition;
                m_ShowingElements.Insert(0, headElement);
            }
        }
예제 #16
0
        public void Reset()
        {
            float   with = m_ElementsAgent.GetInfoCount() * (m_SampleElement.rect.width + m_SpaceBTElements) - m_SpaceBTElements;
            Vector2 size = m_ElementContainer.sizeDelta;

            size.x = with;
            m_ElementContainer.sizeDelta = size;
            IEnumerator <ScrollElement> chipsEnumerator = m_ShowingElements.GetEnumerator();

            chipsEnumerator.Reset();
            while (chipsEnumerator.MoveNext())
            {
                DisPawnElement(chipsEnumerator.Current);
            }
            m_ShowingElements.Clear();
            int headIdx = CountHeadIdx();

            if (headIdx < m_ElementsAgent.GetInfoCount() - 1)
            {
                ScrollElement headElement = SpawnElement();
                AddHead(headElement);
            }
        }
예제 #17
0
        protected override bool IsNeedAddHead()
        {
            if (showingElementsNum <= 0)
            {
                return(true);
            }
            ScrollElement headElement = m_ShowingElements[0];

            if (headElement.idx <= 0)
            {
                return(false);
            }
            Vector2 viewHeadPos = CountHeadPosOfView();
            Vector2 viewTailPos = CountTailPosOfView();

            Vector2 viewVector   = viewTailPos - viewHeadPos;
            Vector2 elmentVector = viewHeadPos - headElement.rect.anchoredPosition;

            if (Vector2.Dot(viewVector, elmentVector) < 0)
            {
                return(true);
            }
            return(false);
        }