} // end OnClickItem private void DragUp(float value) { if (index >= maxIndex) return; // end if if (value > (index - indexGap) * gap) { UIScrollItem item = itemQueue.Dequeue(); item.SetBotton(); item.ResetItem(index.ToString(), null, index.ToString()); itemQueue.Enqueue(item); index++; } // end if } // end DragUp
} // end DragUp private void DragDown(float value) { if (index <= indexGap + 1) return; // end if if (value < (index - indexGap - 1) * gap) { UIScrollItem item = itemQueue.DequeueRev(); item.SetTop(); item.ResetItem(index.ToString(), null, (index - indexGap - 2).ToString()); itemQueue.EnqueueRev(item); index--; } // end if } // end DragDown
public UIScrollView(ScrollRect scrollRect) { index = 0; lastDrag = 0; maxIndex = 100; this.scrollRect = scrollRect; itemQueue = new TWQueue<UIScrollItem>(); scrollRect.content.sizeDelta = new Vector2(383, maxIndex * 125); int count = Mathf.Clamp(maxIndex, 0, 4); indexGap = count - 1; for (int i = 0; i < count; i++) { UIScrollItem item = new UIScrollItem(scrollRect.content, new Vector3(0, -62.5f - i * 125f, 0), OnClickItem); item.ResetItem(index.ToString(), null, index.ToString()); itemQueue.Enqueue(item); index++; } // end for scrollRect.verticalScrollbar.onValueChanged.AddListener(delegate (float value) { OnDrag(value); }); } // end Start