当前位置:网站首页>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
边栏推荐
- 2021.11.10 compilation examination
- [leetcode622]设计循环队列
- Servlet
- (一)R语言入门指南——数据分析的第一步
- Design and implementation of general interface open platform - (39) simple and crude implementation of API services
- Whistle+switchyomega configure web proxy
- FairyGUI增益BUFF數值改變的顯示
- Naive Bayesian theory derivation
- FGUI工程打包发布&导入Unity&将UI显示出来的方式
- Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
猜你喜欢
FairyGUI条子家族(滚动条,滑动条,进度条)
FairyGUI增益BUFF数值改变的显示
NRF24L01 troubleshooting
First use of dosbox
Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
Unity scene jump and exit
NRF24L01故障排查
FairyGUI简单背包的制作
基于Redis的分布式锁 以及 超详细的改进思路
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
随机推荐
Liste des boucles de l'interface graphique de défaillance
Who says that PT online schema change does not lock the table, or deadlock
Halcon knowledge: gray_ Tophat transform and bottom cap transform
Unity3d camera, the keyboard controls the front and rear left and right up and down movement, and the mouse controls the rotation, zoom in and out
Design and implementation of general interface open platform - (39) simple and crude implementation of API services
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
Theoretical derivation of support vector machine
Unity3D,阿里云服务器,平台配置
FairyGUI簡單背包的制作
Latex learning
idea中好用的快捷键
Naive Bayesian theory derivation
Combination of fairygui check box and progress bar
Gateway fails to route according to the service name, and reports an error service unavailable, status=503
What is the maximum length of MySQL varchar field
(课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)
[leetcode622]设计循环队列
FairyGUI增益BUFF數值改變的顯示
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
About using @controller in gateway