当前位置:网站首页>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;
}
}
}
边栏推荐
- [updating] wechat applet learning notes_ three
- C#课程设计之学生教务管理系统
- go 解析身份证
- Easy touch plug-in
- Image processing 8-cnn image classification
- the installer has encountered an unexpected error installing this package
- Unity learning notes
- Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
- Xlua task list youyou
- redis集群系列四
猜你喜欢

UE4 source code reading_ Bone model and animation system_ Animation node

Transfinite hacker cognition

GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库

Chocolate installation

Kunlunbase meetup is waiting for you!

C语言-入门-精华版-带你走进编程(一)

Introduction to hexadecimal coding

A tunnel to all ports of the server

Ue5 opencv plug-in use

图像处理8-CNN图像分类
随机推荐
Abstract classes and interfaces
Development material set
GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
Basic operation and process control 2
Installation of PHP FPM software +openresty cache construction
Advanced OSG collision detection
Maxcompute string splitting function -split_ PART
[usaco12mar]cows in a skyscraper g (state compression DP)
Three characteristics
Golang 时间格式整理
Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)
UE4 source code reading_ Bone model and animation system_ Animation node
Redis data structure
P2704 [noi2001] artillery position (shape pressure DP)
Simply start with the essence and principle of SOM neural network
the installer has encountered an unexpected error installing this package
【更新中】微信小程序学习笔记_3
Osgearth north arrow display
Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
UE4 source code reading_ Bone model and animation system_ Animation process