Exemple #1
0
        public void UpdateState()
        {
            ScrollElement element = Last.Next;            //First;

            for (int i = 0; i < instantateItemCount; i++)
            {
                //Debug.Log(box.ID);
                if (element.ID >= 0 && element.ID < dataList.Count)
                {
                    element.Set(dataList[element.ID]);
                }
                else
                {
                    element.SetActive(false);
                }
                element = element.Next;
            }
        }
Exemple #2
0
        void Init()
        {
            //scrollRect 초기화
            scrollRect.horizontal        = false;
            scrollRect.vertical          = true;
            scrollRect.content           = container;
            scrollRect.scrollSensitivity = 50;
            length = viewPort.rect.height / 5f;

            instantateItemCount = 7;
            beforeAnchoredPos   = anchoredPosition;
            lastItemNo          = instantateItemCount - 1;
            for (int i = 0; i < instantateItemCount; i++)
            {
                ScrollElement element = MakeNewElement(i);
                AddElement(element, i);
                element.SetActive(false);
            }
        }
Exemple #3
0
        public void AddElement(ScrollElement element, int i)
        {
            element.ID = i;
            element.gameObject.SetActive(true);
            ((RectTransform)element.transform).anchoredPosition = new Vector2(0, length * -i);

            if (First != null)
            {
                Last.Next    = element;
                First.Prev   = element;
                element.Prev = Last;
                element.Next = First;
                Last         = element;
            }
            else
            {
                First = Last = element;
            }
        }
Exemple #4
0
        ScrollElement MakeNewElement(int i)
        {
            RectTransform item = Instantiate(elementPrefab) as RectTransform;

            item.SetParent(container, false);

            Vector2 s = item.sizeDelta;

            s.x            = 0;
            s.y            = length;
            item.sizeDelta = s;
            ScrollElement element = item.gameObject.AddComponent <ScrollElement>();

            element.Init(item.GetComponentInChildren <Text>());

            item.GetComponent <Button>().onClick.AddListener(element.Invoke);
            item.transform.GetChild(1).GetComponent <Button>().onClick.AddListener(() =>
            {
                element.Delete();
                RefreshList();
            });
            element.ID = i;
            return(element);
        }
Exemple #5
0
        public void OnValueChanged()
        {
            //가장 위쪽
            if (anchoredPosition > maxPosition)             // 잘 안되면 아이템 리스트 첫번째 좌표값이 minpos보다 작거나 같을때로 변경
            {
                container.anchoredPosition = new Vector2(container.anchoredPosition.x, maxPosition);
                scrollRect.velocity        = Vector2.zero;


                //return;
            }
            //가장 아래쪽
            else if (anchoredPosition < minPosition)            // 악보 가장 오른쪽
            {
                container.anchoredPosition = new Vector2(container.anchoredPosition.x, minPosition);
                scrollRect.velocity        = Vector2.zero;
                //return;
            }
            delta             = beforeAnchoredPos - anchoredPosition;
            beforeAnchoredPos = anchoredPosition;
            //요소들이 아래로 감. 아래로 스크롤. 끝에 있는놈이 처음으로 와야 함.
            if (delta > 0)
            {
                //diff가 anchoredPosition이 될 때까지 length를 계속 뺌.
                while (anchoredPosition < diffPreFramePosition)                //-bitGap* 2 /* &&lastItemNo < DataManager.bitNum*/)
                {
                    diffPreFramePosition -= length;


                    Last.ID = lastItemNo - instantateItemCount;
                    if (Last.ID >= 0 && Last.ID < dataList.Count)
                    {
                        Last.Set(dataList[Last.ID]);
                    }

                    /*if(Last.ID >= 0)
                     * {
                     *      Last.Set(Last.ID);
                     * }*/
                    else
                    {
                        Last.SetActive(false);
                    }
                    ((RectTransform)Last.transform).anchoredPosition = -Vector2.up * (length * Last.ID);
                    Last = Last.Prev;
                    lastItemNo--;
                }
            }
            else if (delta < 0)
            {
                //요소들이 위로 감. 위로 스크롤. 처음에 있는 놈들이 끝으로 가야 됨.
                while (anchoredPosition > diffPreFramePosition + length /*&& firstItemNo > 0*/)
                {
                    diffPreFramePosition += length;

                    lastItemNo++;
                    First    = Last.Next;
                    First.ID = lastItemNo;

                    if (First.ID < dataList.Count)
                    {
                        First.Set(dataList[First.ID]);
                    }

                    /*if (First.ID < dataList.Count)
                     * {
                     *      First.Set(First.ID);
                     * }*/
                    else
                    {
                        First.SetActive(false);
                    }
                    ((RectTransform)First.transform).anchoredPosition = -Vector2.up * (length * First.ID);
                    Last = Last.Next;
                }
            }
        }