public void OnScroll(Vector2 pos) { Vector3 dir = m_ItemContentTransform.localPosition - m_PreviousContentPos; m_PreviousContentPos = m_ItemContentTransform.localPosition; /* * float x = -m_ItemContentTransform.localPosition.x; * x -= m_ItemIconStartPos.x; * x += ITEM_PAD; * * float fIndex = x / ( m_fItemIconWidth + ITEM_PAD ) + 1.0f; * int nIndex = Mathf.Clamp( (int)Mathf.Round( fIndex ), 0, m_ItemIcons.Count - 1 ); */ int nIndex = m_HorizontalScrollSnap.FindClosestIndex(); for (int i = 0; i < m_ItemIcons.Count; ++i) { GameObject itemIcon = m_ItemIcons[i]; SetItemIconEnable(itemIcon, i == nIndex); } if (dir.sqrMagnitude <= HorizontalScrollSnap.SNAP_SPEED) { m_HorizontalScrollSnap.SetScrollStop(); } }