当前位置:网站首页>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 = "空白";
}
}
六、最终效果图
边栏推荐
- Navigator object (determine browser type)
- 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
- ORA-02030: can only select from fixed tables/views
- [Offer18]删除链表的节点
- Page performance optimization of video scene
- Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
- About using @controller in gateway
- VSCode基础配置
- js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
- Arm pc=pc+8 is the most understandable explanation
猜你喜欢
Fashion Gen: the general fashion dataset and challenge paper interpretation & dataset introduction
MySQL時間、時區、自動填充0的問題
Pat 1097 duplication on a linked list (25 points)
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
Learning notes of JS variable scope and function
Unity scene jump and exit
[Red Treasure Book Notes simplified version] Chapter 12 BOM
ES6 grammar summary -- Part 2 (advanced part es6~es11)
There is no red exclamation mark after SVN update
Redis based distributed ID generator
随机推荐
Knowledge summary of request
Minio file download problem - inputstream:closed
VSCode基础配置
Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
Latex learning
MySQL時間、時區、自動填充0的問題
Design and implementation of general interface open platform - (39) simple and crude implementation of API services
MySQL时间、时区、自动填充0的问题
[Offer29] 排序的循环链表
(1) Introduction Guide to R language - the first step of data analysis
2022.2.12 resumption
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
MySQL takes up too much memory solution
[leetcode622]设计循环队列
(课设第一套)1-5 317号子任务 (100 分)(Dijkstra:重边自环)
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
Important methods of array and string
Navigator object (determine browser type)