Unity3D实现列表分页效果
- 作者: 朕心甚悦
- 来源: 51数据库
- 2021-09-05
本文实例为大家分享了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;//更改当前选中的页
}
}
}
}
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
热点文章
团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
0
使用 MSBuild.exe 在发布模式下构建 C# 解决方案
0
当我发布 Web 应用程序时,AfterPublish 脚本不运行
0
构建时 T4 转换的产品仅在下一个构建中使用
0
ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
0
新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
0
如何将条件编译符号(DefineConstants)传递给 msbuild
0
MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
0
NuGet 包还原找不到包,没有源
0
使用 C# 6.0 功能运行 TFS 构建
0
