当前位置:网站首页>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;
}
}
}
边栏推荐
- 使用base64编码传图片
- the installer has encountered an unexpected error installing this package
- Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
- ArrayList
- UE4 call DLL
- Golang's range
- go 解析身份证
- Markdown directory generation
- Unity learning notes
- 基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
猜你喜欢

Haproxy+kept build 01

Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)

About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
![P1596 [USACO10OCT]Lake Counting S](/img/a7/07a84c93ee476788d9443c0add808b.png)
P1596 [USACO10OCT]Lake Counting S

ArrayList

Dealing with duplicate data in Excel with xlwings

UE4 source code reading_ Bone model and animation system_ Animation compression

VIM learning notes from introduction to silk skating

Easy touch plug-in

A tunnel to all ports of the server
随机推荐
Easy touch plug-in
L'installateur a été installé avec une erreur inattendue
Golang的range
About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Swagger document configuration
Yolo series --- xml2txt script
UE4 source code reading_ Mobile synchronization
the installer has encountered an unexpected error installing this package
Animation_ IK overview
Haproxy+kept build 01
E: Unable to locate package ROS melody desktop full
C language - Introduction - essence Edition - take you into programming (I)
Osgearth target selection
[K & R] Chinese Second Edition personal questions Chapter1
Image processing 8-cnn image classification
Unity learning notes
Simple demo of solving BP neural network by gradient descent method
Golang's range
Dealing with duplicate data in Excel with xlwings