【生意多】-免费发布分类信息
当前位置: 首页 » 新闻 » 教程 » 正文

Unity UGUI实现滑动翻页效果

放大字体  缩小字体 发布日期:2021-12-11 05:47:00    浏览次数:7
导读

  本文实例为大家分享了Unity UGUI实现滑动翻页效果的具体代码,供大家参考,具体内容如下  这个问题真的是老生常谈的事情了,不过在这里还是要说一下,以便以后之需  首先看一下效果图  最后在Content下面是一些Image   ntal = 0; //滑动的起始坐标 private bool isDrag = false; //是否拖拽结束 private List p

  本文实例为大家分享了Unity UGUI实现滑动翻页效果的具体代码,供大家参考,具体内容如下

  这个问题真的是老生常谈的事情了,不过在这里还是要说一下,以便以后之需

  首先看一下效果图

  最后在Content下面是一些Image

   ntal = 0; //滑动的起始坐标 private bool isDrag = false; //是否拖拽结束 private List posList = new List ();//求出每页的临界角,页索引从0开始 private int currentPageIndex = -1; public Action OnPageChanged; private bool stopMove = true; public float smooting = 4; //滑动速度 public float sensitivity = 0; private float startTime; private float startDragHorizontal; void Awake () { // rect = rect2; rect = transform.GetComponent (); // rect2 = transform.GetComponent(); float horizontalLength = rect.content.rect.width - GetComponent ().rect.width; //float horizontalLength2 = rect2.content.rect.width - GetComponent().rect.width; posList.Add (0); for(int i = 1; i ().rect.width * i / horizontalLength); } posList.Add (1); } void Update () { if(!isDrag && !stopMove) { startTime += Time.deltaTime; float t = startTime * smooting; rect.horizontalNormalizedPosition = Mathf.Lerp (rect.horizontalNormalizedPosition , targethorizontal , t); // rect2.horizo= 0 && index ntalNormalizedPosition = posList[index]; SetPageIndex(index); } else { Debug.LogWarning (页码不存在); } } private void SetPageIndex (int index) { if(currentPageIndex != index) { currentPageIndex = index; if(onPageChanged != null) onPageChanged (index); } } public void onBeginDrag (PointerEventData eventData) { isDrag = true; startDragHorizontal = rect.horizontalNormalizedPosition; // startDragHorizontal = rect2.horizontalNormalizedPosition; } public void onEndDrag (PointerEventData eventData) { float posX = rect.horizontalNormalizedPosition; posX += ((posX - startDragHorizontal) * sensitivity); posX = posX 0 ? posX : 0; int index = 0; float offset = Mathf.Abs (posList[index] - posX); for(int i = 1; i ntal = posList[index]; //设置当前坐标,更新函数进行插值 isDrag = false; startTime = 0; stopMove = false; } }

  最后看一下,怎么设置的:

  剩下的就没有什么了。

  以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

 
关键词: 考试
(文/小编)
打赏
免责声明
• 
本文为小编原创作品,作者: 小编。欢迎转载,转载请注明原文出处:https://www.31duo.com/news/show-2280412.html 。本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们。
 

(c)2016-2019 31DUO.COM All Rights Reserved浙ICP备19001410号-4

浙ICP备19001410号-4