Unity3D实现列表分页效果
2020-04-18 07:11
741 查看
本文实例为大家分享了Unity3D实现列表分页效果的具体代码,供大家参考,具体内容如下
using System.Collections.Generic; using UnityEngine; public class Page : MonoBehaviour { public List<string> Tips = new List<string>(); public Texture2D DetailImg1; public Texture2D DetailImg2; private int pageCount = 0;//当前记录所需页数 private static int currentPage = 1;//当前页码 void OnGUI() { pageCount = Mathf.CeilToInt(Tips.Count / 8.0f);//计算当前的页码总数 int m_count = 0;//计算当前页的记录数 if (currentPage != pageCount)//判断是否是最后一页,若不是则每页绘制8条记录 { m_count = 8; } else { if (Mathf.CeilToInt((Tips.Count + 1) / 8.0f) > pageCount)//判断最后一页是否有8条记录 { m_count = 8; } else { m_count = Tips.Count % 8;//计算最后一页的记录数 } } for (int i = 0; i < m_count; i++) { if (i % 2 == 0) { GUI.DrawTexture(new Rect(268, 253 + i * 36, 487, 36), DetailImg1); } else { GUI.DrawTexture(new Rect(268, 253 + i * 36, 487, 36), DetailImg2); } GUI.Label(new Rect(310, 253 + i * 36, 300, 36), Tips[(currentPage - 1) * 8 + i]); } //超过一页内容时,显示页码跳转 if (pageCount > 1) { float temp = Screen.width / 2 - pageCount / 2 * 20; for (int i = 1; i <= pageCount; ++i) { //更改按钮样式 if (currentPage == i) { GUI.backgroundColor = Color.red; } else { GUI.backgroundColor = Color.white; } //绘制按钮 if (GUI.Button(new Rect(temp + 20 * i, 600, 20, 20), i.ToString())) { currentPage = i;//更改当前选中的页 } } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- Kotlin实战案例:带你实现RecyclerView分页查询功能(仿照主流电商APP,可切换列表和网格效果)
- vue2.0与bootstrap3实现列表分页效果
- sharepoint2010列表的分页实现迅雷样式效果
- Ajax实现phpcms列表分页效果
- sharepoint2010列表的分页实现迅雷样式效果
- jQuery实现仿腾讯视频列表分页效果的方法
- 利用jQuery和css实现的模仿百度搜索列表页面的分页的足迹效果
- jQuery实现仿腾讯视频列表分页效果的方法
- 基于jqGrid实现列表分页效果(后台处理以及pageBean)
- salesforce 零基础学习(四十九)自定义列表分页之使用Pagination实现分页效果 ※※※
- [Unity3d]汽车的前照灯的效果实现
- Unity3D 实现六角形花纹效果
- Unity3D --实现一个物体若隐若现的效果
- Unity3D Shader实现贴图切换效果
- jquery实现鼠标点击后展开列表内容的导航栏效果
- Unity3D NGUI蒙版效果实现方法
- 用slice实现分页效果
- 【Unity3D】如何用实现MC中整齐创建物体的效果?
- 水平列表导航菜单效果实现
- 分页学习总结-2-自定义标签实现分页效果-1