当前位置:网站首页>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 = "空白";
}
}
六、最终效果图
边栏推荐
- ES6 grammar summary -- Part I (basic)
- Cannot change version of project facet Dynamic Web Module to 2.3.
- Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
- Redis based distributed ID generator
- 1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
- 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
- MySQL time, time zone, auto fill 0
- [leetcode15] sum of three numbers
- Arduino uno R3 register writing method (1) -- pin level state change
- VIM command line notes
猜你喜欢
Vulnhub target: hacknos_ PLAYER V1.1
数据库课程设计:高校教务管理系统(含代码)
Redis based distributed locks and ultra detailed improvement ideas
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
SVN更新后不出现红色感叹号
Idea problem record
Easy to use shortcut keys in idea
js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
单片机蓝牙无线烧录
MySQL时间、时区、自动填充0的问题
随机推荐
[899] ordered queue
[offer78]合并多个有序链表
Générateur d'identification distribué basé sur redis
MySQL占用内存过大解决方案
Conditional probability
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
There is no red exclamation mark after SVN update
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
JS 函数提升和var变量的声明提升
VSCode基础配置
[offer29] sorted circular linked list
Esp8266 uses Arduino to connect Alibaba cloud Internet of things
2021.11.10汇编考试
(课设第一套)1-4 消息传递接口 (100 分)(模拟:线程)
Common properties of location
idea中好用的快捷键
[leetcode19] delete the penultimate node in the linked list
JS variable types and common type conversions
(五)R语言入门生物信息学——ORF和序列分析