当前位置:网站首页>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
边栏推荐
- Minio file download problem - inputstream:closed
- (5) Introduction to R language bioinformatics -- ORF and sequence analysis
- Easy to use shortcut keys in idea
- [leetcode19]删除链表中倒数第n个结点
- JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
- Gateway fails to route according to the service name, and reports an error service unavailable, status=503
- Working principle of genius telephone watch Z3
- First use of dosbox
- JS regular expression basic knowledge learning
- Navigator object (determine browser type)
猜你喜欢
The dolphin scheduler remotely executes shell scripts through the expect command
FairyGUI复选框与进度条的组合使用
程序设计大作业:教务管理系统(C语言)
(1) Introduction Guide to R language - the first step of data analysis
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
单片机蓝牙无线烧录
Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
Basic operations of databases and tables ----- classification of data
基於Redis的分布式ID生成器
level16
随机推荐
NRF24L01故障排查
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
Minio文件下载问题——inputstream:closed
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
Who says that PT online schema change does not lock the table, or deadlock
C programming exercise
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
[Leetcode15]三数之和
[offer18] delete the node of the linked list
MySQL error warning: a long semaphore wait
Design and implementation of general interface open platform - (39) simple and crude implementation of API services
How to add music playback function to Arduino project
Game 280 weekly
單片機藍牙無線燒錄
HCIP Day 12
Basic operations of databases and tables ----- modifying data tables
JUC forkjoin and completable future
Talking about the startup of Oracle Database
SSD technical features