当前位置:网站首页>Fabrication of fairygui simple Backpack
Fabrication of fairygui simple Backpack
2022-07-06 12:38:00 【SQ Liu】
FairyGUI Making of simple Backpack
Results the preview :
One 、 Create a new project

Rename it 
Two 、 Make backpack pop-up
1、 Create a new container component for the backpack (BagWindow)


2、 Create a new window frame component (WindowFrame)

3、 Import material resources
4、 stay WindowFrame In the operation
(1) Drag into the background of the backpack

And will n0 Rename it to BG( Backpack background )
(2) New close button (ButtonClose)


(3) Create a new graphic as a placeholder (dragArea—— Drag area )

5、 stay BagWindow In the operation
(1) take WindowFrame Drag in BagWindow, And set its component size

(2) Drag into the list to load game objects

(3) Make a grid in the list —— The new button Item

(4) edit Item
Drag into the background 
Drag in Title

Drag loader 
6、 stay Main In the operation
(1) Make a picture display button ItemView

(2) Yes ItemView Make some improvements

(3) New backpack pop-up button BagButton

(4) double-click BagButton Button to edit it

7、 go back to BagWindow, Assign a value to


rename , Make some small changes .
3、 ... and 、 Package, export and publish



Four 、Unity It shows that
1、 newly build Unity project

2、 Download from the resource store FairyGUI
When importing after downloading , You need to pay attention to , To put Examples Below Bag Delete the . Because it was not deleted before importing , It leads to some strange phenomena behind .

3、Unity It shows that

5、 ... and 、 Code control
1、 Create two new scripts
One is the backpack pop-up script BagWindow, One is the main script Bag.

2、 Edit script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class BagWindow : Window
{
public BagWindow()
{
}
protected override void OnInit()
{
this.contentPane = UIPackage.CreateObject("Bag", "BagWindow").asCom;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class Bag : MonoBehaviour
{
private GComponent mainUI;
private GButton playerView;
private BagWindow bagWindow;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
playerView = mainUI.GetChild("playerView").asButton;
playerView.onClick.Add(UseItem);
bagWindow = new BagWindow();
mainUI.GetChild("bagButton").onClick.Add(() => {
bagWindow.Show(); });
}
// Update is called once per frame
void Update()
{
}
private void UseItem()
{
}
}
3、 Running effect

4、 Load the contents of the backpack
(1) Change my BagWindow List names in :itemList, as well as ItemView Inside title, And redistribute


(2) Continue coding to realize the function
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class BagWindow : Window
{
private GList list;
private GButton playerView;
public BagWindow(GButton targetButton)
{
playerView = targetButton;
}
protected override void OnInit()
{
this.contentPane = UIPackage.CreateObject("Bag", "BagWindow").asCom;
list = this.contentPane.GetChild("itemList").asList;
list.itemRenderer = RenderListItem;
list.numItems = 20;
for (int i = 0; i < list.numItems - 10; i++)
{
GButton button = list.GetChildAt(i).asButton;
button.onClick.Add(() => {
ClickItem(button); });
}
}
private void RenderListItem(int index, GObject obj)
{
GButton button = obj.asButton;
button.icon = UIPackage.GetItemURL("Bag", "i" + index);
button.title = index.ToString();
}
private void ClickItem(GButton button)
{
playerView.title = button.title;
playerView.icon = button.icon;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class Bag : MonoBehaviour
{
private GComponent mainUI;
private GButton playerView;
private BagWindow bagWindow;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
playerView = mainUI.GetChild("playerView").asButton;
playerView.onClick.Add(UseItem);
bagWindow = new BagWindow(playerView);
bagWindow.SetXY(121, 63); // Set the initial position where the backpack pop-up window appears
mainUI.GetChild("bagButton").onClick.Add(() => {
bagWindow.Show(); });
}
private void UseItem()
{
playerView.icon = null;
playerView.title = " blank ";
}
}
6、 ... and 、 Final rendering


边栏推荐
- Use of lists
- Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
- 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
- 数据库课程设计:高校教务管理系统(含代码)
- [899] ordered queue
- 燕山大学校园网自动登录问题解决方案
- Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
- [leetcode622] design circular queue
- Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
- Walk into WPF's drawing Bing Dwen Dwen
猜你喜欢

JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
![Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]](/img/b0/176bf6dea2201afc892d6750c5974b.png)
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]

(5) Introduction to R language bioinformatics -- ORF and sequence analysis

Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)

Programming homework: educational administration management system (C language)

There is no red exclamation mark after SVN update

MySQL时间、时区、自动填充0的问题

(1) Introduction Guide to R language - the first step of data analysis

2021.11.10汇编考试

Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
随机推荐
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
(五)R语言入门生物信息学——ORF和序列分析
Minio file download problem - inputstream:closed
@Autowired 和 @Resource 的区别
Basic operations of databases and tables ----- classification of data
Knowledge summary of request
Latex learning
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
Gateway fails to route according to the service name, and reports an error service unavailable, status=503
Vscode basic configuration
The dolphin scheduler remotely executes shell scripts through the expect command
MySQL performance tuning - dirty page refresh
Guided package method in idea
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Arduino JSON data information parsing
1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
History object
Single chip Bluetooth wireless burning
Force buckle 1189 Maximum number of "balloons"