Ngui 左右滑动

来源:互联网 发布:北面和狼爪哪个好 知乎 编辑:程序博客网 时间:2024/06/05 14:16

实现效果图:


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


0 0
原创粉丝点击