当前位置:网站首页>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
边栏推荐
- Teach you to release a DeNO module hand in hand
- @Autowired 和 @Resource 的区别
- Générateur d'identification distribué basé sur redis
- 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
- Get the position of the nth occurrence of the string
- 基於Redis的分布式ID生成器
- Unity3D制作注册登录界面,并实现场景跳转
- First use of dosbox
- There is no red exclamation mark after SVN update
- [offer78]合并多个有序链表
猜你喜欢
idea问题记录
FGUI工程打包发布&导入Unity&将UI显示出来的方式
Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
MySQL時間、時區、自動填充0的問題
FairyGUI按钮动效的混用
JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
MySQL time, time zone, auto fill 0
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
[Nodejs] 20. Koa2 onion ring model ----- code demonstration
Liste des boucles de l'interface graphique de défaillance
随机推荐
FGUI工程打包发布&导入Unity&将UI显示出来的方式
[Offer18]删除链表的节点
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
idea问题记录
Types de variables JS et transformations de type communes
Fabrication d'un sac à dos simple fairygui
[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data
基于Redis的分布式锁 以及 超详细的改进思路
2022.2.12 resumption
Force buckle 1189 Maximum number of "balloons"
Special palindromes of daily practice of Blue Bridge Cup
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
MySQL时间、时区、自动填充0的问题
idea中导包方法
JS variable types and common type conversions
MySQL replacement field part content
Talking about the startup of Oracle Database
Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
SSD technical features