当前位置:网站首页>FairyGUI简单背包的制作
FairyGUI简单背包的制作
2022-07-06 09:18:00 【SQ刘】
FairyGUI简单背包的制作
效果预览:
一、创建新项目
重命名一下
二、制作背包弹窗
1、新建背包的容器组件(BagWindow)
2、新建窗口框架组件(WindowFrame)
3、导入素材资源
4、在WindowFrame中操作
(1)拖入背包的背景
并将n0重命名为BG(即背包背景)
(2)新建关闭按钮(ButtonClose)
(3)新建图形作为一个占位(dragArea——拖拽区域)
5、在BagWindow中操作
(1)将WindowFrame拖入BagWindow,并设置其组件大小
(2)拖入列表承载游戏物体
(3)在列表中制作格子——新建按钮Item
(4)编辑Item
拖入背景图
拖入Title
拖入装载器
6、在Main中操作
(1)制作图片显示按钮ItemView
(2)对ItemView做一些完善
(3)新建背包弹窗按钮BagButton
(4)双击BagButton按钮对它进行编辑
7、回到BagWindow,对其赋值
重命名,做一些小小的更改。
三、打包导出发布
四、Unity中显示
1、新建Unity项目
2、下载资源商店里的FairyGUI
下载后导入时,需要注意一下,要把Examples下面的Bag删除掉。因为之前导入的时候就是没有删除,导致后面出现一些奇奇怪怪的现象。
3、Unity中显示
五、代码控制
1、新建两个脚本
一个是背包弹窗脚本BagWindow,一个是主要脚本Bag。
2、编辑脚本
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、运行效果
4、加载背包里的内容
(1)更改一下BagWindow里的列表名字:itemList,以及ItemView里的title,并重新发布
(2)继续编码实现功能
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); //设置背包弹窗出现的初始位置
mainUI.GetChild("bagButton").onClick.Add(() => {
bagWindow.Show(); });
}
private void UseItem()
{
playerView.icon = null;
playerView.title = "空白";
}
}
六、最终效果图
边栏推荐
- @The difference between Autowired and @resource
- [offer9]用两个栈实现队列
- 1041 be unique (20 points (s)) (hash: find the first number that occurs once)
- About using @controller in gateway
- [golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
- [899] ordered queue
- Arduino get random number
- Whistle+switchyomega configure web proxy
- SSD technical features
- open-mmlab labelImg mmdetection
猜你喜欢
Basic operations of databases and tables ----- modifying data tables
Derivation of logistic regression theory
Common properties of location
Vulnhub target: hacknos_ PLAYER V1.1
MySQL时间、时区、自动填充0的问题
(五)R语言入门生物信息学——ORF和序列分析
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
Redis based distributed ID generator
Cannot change version of project facet Dynamic Web Module to 2.3.
Whistle+switchyomega configure web proxy
随机推荐
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Solution to the problem of automatic login in Yanshan University Campus Network
Basic operations of databases and tables ----- classification of data
[899] ordered queue
Redis based distributed ID generator
单片机蓝牙无线烧录
数据库课程设计:高校教务管理系统(含代码)
[esp32 learning-2] esp32 address mapping
2022.2.12 resumption
Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
@The difference between Autowired and @resource
level16
ES6 grammar summary -- Part 2 (advanced part es6~es11)
Easy to use shortcut keys in idea
Naive Bayesian theory derivation
Arduino get random number
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
Walk into WPF's drawing Bing Dwen Dwen
(课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)
First use of dosbox