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; } }
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); } }
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; } } }