当前位置:网站首页>Fairygui loop list
Fairygui loop list
2022-07-06 12:46:00 【SQ Liu】
FairyGUI Loop list
Realization effect : stay Unity in , You can cycle through the list with the mouse , And when browsing the current page , It has an effect of being close to big and far away .
One 、 Import resources
Two 、 The new button
3、 ... and 、 Design list
Four 、 Loader dynamic load picture button
If there are tens of thousands of buttons , We can't create one by one , It's time to be in Unity Resources for dynamically loading picture buttons in , Therefore, the loader is introduced .
Button size is 248×378, Then the loader should also be 248×378. Then classify its position as 0,0.
Enter the list again , Add a few more objects to it .
5、 ... and 、 Packaging releases
6、 ... and 、Unity It shows that
7、 ... and 、 Write code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class LoopList : MonoBehaviour
{
private GComponent mainUI;
private GList list;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
list = mainUI.GetChild("n0").asList; //n0 yes FairyGUI List in
list.SetVirtualAndLoop(); // Set the list as a virtual list (FGUI Regulations : If you use lists , You must use a virtual list )
list.itemRenderer = RenderListItem; // call list The rendering function inside , It is a delegate type variable , So assign it a method
list.numItems = 5; // Set the length of the list
}
private void RenderListItem(int index, GObject obj)
{
GButton button = obj.asButton;
button.icon = UIPackage.GetItemURL("LoopList", "n" + (index + 1)); // Get dynamic URL
}
}
Compile operation , go back to Unity Found an error . Originally in FairyGUI Forgot to drag project resources into , Manually drag it .
Republish it again
here , go back to Unity, The operation results are as follows . Find out “ Chapter two ”、“ The third chapter ” The pictures below are “ Chapter one ” The picture below . What's the reason ? Because before we were FairyGUI I have been given Button1 A rendering , Obviously this is not possible . So we need to render and delete its own image . Directly through icon Just load it .
Another place is , find LoopList list , Set its overflow handling to “ Horizontal scrolling ”.
Release again , All working well .
8、 ... and 、 Running effect
Nine 、 Further refinement —— Special effects of near, far and small
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class LoopList : MonoBehaviour
{
private GComponent mainUI;
private GList list;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
list = mainUI.GetChild("n0").asList; //n0 yes FairyGUI List in
list.SetVirtualAndLoop(); // Set the list as a virtual list (FGUI Regulations : If you use lists , You must use a virtual list )
list.itemRenderer = RenderListItem; // call list The rendering function inside , It is a delegate type variable , So assign it a method
list.numItems = 5;
list.scrollPane.onScroll.Add(DoSpecialEffect);
DoSpecialEffect();
}
private void DoSpecialEffect()
{
float listCenter = list.scrollPane.posX + list.viewWidth / 2;
//scrollPane Is the width of the current list ;viewWidth Is the width of the list itself
for (int i = 0; i < list.numChildren; i++) //numChildren Is the currently rendered object , That's the runtime Game The number that can be seen in
{
GObject item = list.GetChildAt(i);
float itemCenter = item.x + item.width / 2;
float itemWidth = item.width;
float distance = Mathf.Abs(listCenter - itemCenter);
if (distance < itemWidth)
{
float distanceRange = 1 + (1 - distance / itemWidth) * 0.2f;
item.SetScale(distanceRange, distanceRange);
}
else
{
item.SetScale(1, 1);
}
}
}
private void RenderListItem(int index, GObject obj)
{
GButton button = obj.asButton;
button.SetPivot(0.5f, 0.5f); // Set the anchor point as the center
button.icon = UIPackage.GetItemURL("LoopList", "n" + (index + 1)); // Get dynamic URL
}
}
Associate the list and button with the container respectively
After being released in Unity There will be no problem in running .
Ten 、 The final perfect rendering
边栏推荐
- [Offer29] 排序的循环链表
- Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
- Database table splitting strategy
- 数据库课程设计:高校教务管理系统(含代码)
- Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
- Lock wait timeout exceeded try restarting transaction
- 單片機藍牙無線燒錄
- 关于Gateway中使用@Controller的问题
- Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
- @Autowired 和 @Resource 的区别
猜你喜欢
Générateur d'identification distribué basé sur redis
Pytorch: tensor operation (I) contiguous
2021.11.10 compilation examination
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
(一)R语言入门指南——数据分析的第一步
JS variable types and common type conversions
Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
Single chip Bluetooth wireless burning
随机推荐
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
关于Gateway中使用@Controller的问题
Teach you to release a DeNO module hand in hand
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
(the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
[offer9] implement queues with two stacks
Types de variables JS et transformations de type communes
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
MySQL time, time zone, auto fill 0
[leetcode15] sum of three numbers
[Offer29] 排序的循环链表
(四)R语言的数据可视化——矩阵图、柱状图、饼图、散点图与线性回归、带状图
[899]有序队列
FairyGUI条子家族(滚动条,滑动条,进度条)
[leetcode19]删除链表中倒数第n个结点
Agile development helps me
FairyGUI人物状态弹窗
[offer9]用两个栈实现队列
2021.11.10汇编考试
Halcon knowledge: gray_ Tophat transform and bottom cap transform