当前位置:网站首页>Unity editor expansion - scrolling list
Unity editor expansion - scrolling list
2022-07-03 08:26:00 【T.D.C】
Scroll through the list
- Do not engage in the pull-down loading of the mobile terminal , Pull up to refresh
- Use paging and page skipping to display list data
- This article provides a custom scrolling list with page turning function
design sketch

To construct a scrolling list API
// The following need to appear in pairs
GUILayout.BeginScrollView
GUILayout.EndScrollView
GUILayout.BeginVertical
GUILayout.EndVertical
GUILayout.BeginHorizontal
GUILayout.EndHorizontal
//Unity The scrolling list of the editor is to place a vertical or horizontal layout component containing content in the middle of the scrolling view
Code
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace DC.DCIMGUIBox
{
public struct ListViewUserData
{
public Vector2 pos;
public int pageIndex;
public int onePageCnt;
public int newPageIndex;
public ListViewUserData(Vector2 pos, int pageIndex, int onePageCnt, int newPageIndex)
{
this.pos = pos;
this.pageIndex = pageIndex;
this.onePageCnt = onePageCnt;
this.newPageIndex = newPageIndex;
}
}
public class ScrollWindow_03 : EditorWindow
{
[MenuItem("DC/IMGUI/ScrollWindow_03")]
public static void Open()
{
var window = GetWindow<ScrollWindow_03>();
window.minSize = new Vector2(800, 600);
}
List<int> dataListA = new List<int>();
private ListViewUserData listInfo = new ListViewUserData(Vector2.zero, 0, 20, 0);
void OnGUI()
{
if (dataListA.Count == 0)
{
for (int i = 0; i < 100; i++)
{
dataListA.Add(i);
}
}
listInfo = ScrollList(listInfo, true, dataListA, Render,
new GUILayoutOption[] {GUILayout.Width(200), GUILayout.Height(200)},
new GUILayoutOption[] { });
}
public void Render<T>(int index, T data)
{
GUILayout.Label(string.Format("id:{0} name:{1}", index, index));
}
public ListViewUserData ScrollList<T>(ListViewUserData listInfo, bool vertical, List<T> dataList,
Action<int, T> renderFunc, GUILayoutOption[] svLp, GUILayoutOption[] containerLp)
{
var startIndex = listInfo.pageIndex * listInfo.onePageCnt;
if (startIndex < 0)
{
return listInfo;
}
if (dataList.Count == 0)
{
GUILayout.Label("dataList is empty! An empty list ");
return listInfo;
}
if (startIndex > dataList.Count)
{
GUILayout.Label("page index is too big! The maximum number of pages is exceeded ");
return listInfo;
}
// Header
GUILayout.BeginHorizontal();
EditorGUILayout.LabelField(" Page number ", GUILayout.Width(30));
listInfo.newPageIndex = Math.Max(0, EditorGUILayout.IntField(listInfo.newPageIndex, GUILayout.Width(30)));
EditorGUILayout.LabelField(" Each page shows ", GUILayout.Width(50));
listInfo.onePageCnt = Math.Max(1, EditorGUILayout.IntField(listInfo.onePageCnt, GUILayout.Width(30)));
if (GUILayout.Button(" Jump ", GUILayout.Width(40)))
{
listInfo.pageIndex = listInfo.newPageIndex;
if (vertical)
{
listInfo.pos.y = 0;
}
else
{
listInfo.pos.x = 0;
}
}
GUILayout.EndHorizontal();
// list
listInfo.pos = GUILayout.BeginScrollView(listInfo.pos, svLp);
var endIndex = Math.Min(startIndex + listInfo.onePageCnt, dataList.Count);
if (vertical)
{
GUILayout.BeginVertical(containerLp);
}
else
{
GUILayout.BeginHorizontal(containerLp);
}
for (int i = startIndex; i < endIndex; i++)
{
renderFunc(i, dataList[i]);
}
if (vertical)
{
GUILayout.EndVertical();
}
else
{
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
return listInfo;
}
}
}
边栏推荐
- Markdown directory generation
- Easy touch plug-in
- Redis cluster series 4
- GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
- How to establish rectangular coordinate system in space
- Golang time format sorting
- the installer has encountered an unexpected error installing this package
- go 解析身份证
- Notes on understanding applets 2022/7/3
- Osgearth topographic shading map drawing
猜你喜欢

【更新中】微信小程序学习笔记_3

MySQL 8
![P1596 [USACO10OCT]Lake Counting S](/img/a7/07a84c93ee476788d9443c0add808b.png)
P1596 [USACO10OCT]Lake Counting S

UE4 source code reading_ Bone model and animation system_ Animation node

OpenGL learning notes

About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed

Youyou1 of xlua knapsack system

数据分析练习题

A tunnel to all ports of the server

ArrayList
随机推荐
Development material set
【更新中】微信小程序学习笔记_3
KunlunBase MeetUP 等您来!
Base64和Base64URL
P1596 [USACO10OCT]Lake Counting S
Markdown directory generation
the installer has encountered an unexpected error installing this package
One dimensional array two dimensional array (sort Max insert sort)
Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
Golang json格式和结构体相互转换
[K & R] Chinese Second Edition personal questions Chapter1
C#课程设计之员工信息管理系统
Go resolve ID card
Youyou1 of xlua knapsack system
Basic operation and process control 2
Multi traveling salesman problem -- overview of formula and solution process
php-fpm软件的安装+openresty高速缓存搭建
animation
796 · unlock
Swagger document configuration