您的位置:首页 > 产品设计 > UI/UE

Ngui 左右滑动

2016-03-16 15:12 169 查看
实现效果图:



private UIScrollView fubenScrollView;
private UIGrid fubenGrid;
public void OnBtnRight()//右btn
{
if (fubenScrollView == null || fubenGrid == null)
return;

int curIndex = GetFubenScrollViewIndex();

Vector3 targetPos = new Vector3(-(curIndex + 1) * fubenGrid.cellWidth, fubenScrollView.transform.localPosition.y, 0);

CapterData chapterData;
if (CapterManager.Instance.getCapterDataById(currentChapterId.ToString(), out chapterData))
{
List<int> fubenIds = chapterData.Commonfubens;

if (targetPos.x < - ((fubenIds.Count - 4) * fubenGrid.cellWidth + 10))
{
return;
}
}

SpringPanel.Begin(fubenScrollView.panel.cachedGameObject, targetPos, 6f);
}

public void OnBtnLeft()//左btn
{
if (fubenScrollView == null || fubenGrid == null)
return;

int curIndex = GetFubenScrollViewIndex();

Vector3 targetPos = new Vector3(-(curIndex - 1) * fubenGrid.cellWidth, fubenScrollView.transform.localPosition.y, 0);

if (targetPos.x > 10)
{
return;
}

SpringPanel.Begin(fubenScrollView.panel.cachedGameObject, targetPos, 6f);
}

private int GetFubenScrollViewIndex()
{
if (fubenScrollView == null || fubenGrid == null)
return 0;

return Mathf.Abs(Mathf.RoundToInt(fubenScrollView.transform.localPosition.x / fubenGrid.cellWidth));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: