I was use the UGUI,
one page is show six itemelement,
when I drop the scroll view, is there a way to know which itemelement is visible in the scroll view?
I was use the UGUI,
one page is show six itemelement,
when I drop the scroll view, is there a way to know which itemelement is visible in the scroll view?
Well, I have reached some good utility exist in Unity3d, I hope this helps:
RectTransformUtility.RectangleContainsScreenPoint
myself fix this question,
first: Get the count to show in the scroll view.
private int CalculateCurElementShowCount()
{
float offsetCellX = 10.0f;
float offsetCellY = 10.0f;
ColumnElementCount = -1;
RowElementCount = -1;
if (UI_GridGroup.constraint == GridLayoutGroup.Constraint.FixedColumnCount)
{
ColumnElementCount = UI_GridGroup.constraintCount;
}
else if(UI_GridGroup.constraint == GridLayoutGroup.Constraint.FixedRowCount)
{
RowElementCount = UI_GridGroup.constraintCount;
}
if(ColumnElementCount == -1)
{
ColumnElementCount = (int)( (rectComponent.rect.width + offsetCellX)/(UI_GridGroup.cellSize.x + UI_GridGroup.spacing.x) );
}
if(RowElementCount == -1)
{
RowElementCount = (int)( (rectComponent.rect.height + offsetCellY) / (UI_GridGroup.cellSize.y + UI_GridGroup.spacing.y) );
}
int Count = ColumnElementCount * RowElementCount;
if(Count < 0)
{
Count = 0;
}
return Count;
}
second:
float showPercent = 1 - ScrollRectConl.verticalNormalizedPosition;
int centerIndex = (int)(CurAssetList.Count * showPercent);
int halfOffsetIndex = (int)(ScrollShowCount / 2.0f);
downloadLogoStartIndex = ((centerIndex + halfOffsetIndex) >= CurAssetList.Count) ? (centerIndex - ScrollShowCount - ColumnElementCount) : (centerIndex - halfOffsetIndex - ColumnElementCount);
downloadLogoEndIndex = (centerIndex < halfOffsetIndex) ? (centerIndex + ScrollShowCount + ColumnElementCount) : (centerIndex + halfOffsetIndex + ColumnElementCount);
if (downloadLogoStartIndex < 0)
{
downloadLogoStartIndex = 0;
}
if (downloadLogoEndIndex >= CurAssetList.Count)
{
downloadLogoEndIndex = CurAssetList.Count - 1;
}