当前位置:网站首页>FairyGUI按钮动效的混用
FairyGUI按钮动效的混用
2022-07-06 09:18:00 【SQ刘】
FairyGUI按钮动效的混用
一、FGUI中的设计
(一)导入素材资源




原本还有一个音乐素材,导不进来,大家可以自己网上找个类似的背景音乐自行导入。
(二)详细设计
1、新建按钮并对其做一些微调

微调的目的是给按钮一些特效,比如点击时有一个缩放效果,并且有一个音效。
2、按钮拖入Component1中并新建一个文本
将文本与按钮做一个关联,防止后续操作过程中出现一些问题。

3、制作特效
(1)新建组件

(2)特效制作


4、打包导入Unity



二、Unity中的代码实现
1、手动显示按钮




2、脚本代码控制

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class ButtonEffects : MonoBehaviour
{
private GComponent mainUI;
private GComponent bossCom;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
bossCom = UIPackage.CreateObject("Package1", "Boss").asCom;
mainUI.GetChild("n0").onClick.Add(() => {
PlayUI(bossCom); }); //n0是FGUI中的Button1。Add()里面是λ表达式
}
// Update is called once per frame
void Update()
{
}
private void PlayUI(GComponent targetCom)
{
mainUI.GetChild("n0").visible = false;
GRoot.inst.AddChild(targetCom);
Transition t = targetCom.GetTransition("t0"); //t0是Boss的动效
t.Play(()=>
{
mainUI.GetChild("n0").visible = true;
GRoot.inst.RemoveChild(targetCom);
});
}
}

运行效果:
美中不足的是:点击后,这个字体“Boss”并不能消失。这时就需要用到FairyGUI里面的组。
3、创建组重新发布



4、对代码做一些更改
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class ButtonEffects : MonoBehaviour
{
private GComponent mainUI;
private GComponent bossCom;
private GGroup group;
void Start()
{
mainUI = GetComponent<UIPanel>().ui;
group = mainUI.GetChild("n2").asGroup;
bossCom = UIPackage.CreateObject("Package1", "Boss").asCom;
mainUI.GetChild("n0").onClick.Add(() => {
PlayUI(bossCom); });
//n0是FGUI中的Button1。Add()里面是λ表达式
}
// Update is called once per frame
void Update()
{
}
private void PlayUI(GComponent targetCom)
{
//mainUI.GetChild("n0").visible = false;
group.visible = false;
GRoot.inst.AddChild(targetCom);
Transition t = targetCom.GetTransition("t0"); //t0是Boss的动效
t.Play(()=>
{
//mainUI.GetChild("n0").visible = true;
group.visible = true;
GRoot.inst.RemoveChild(targetCom);
});
}
}
三、最终运行效果

边栏推荐
- ES6 grammar summary -- Part I (basic)
- In 2020, the average salary of IT industry exceeded 170000, ranking first
- 数据库课程设计:高校教务管理系统(含代码)
- PT OSC deadlock analysis
- [golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
- SSD technical features
- [899] ordered queue
- Unity3D,阿里云服务器,平台配置
- (四)R语言的数据可视化——矩阵图、柱状图、饼图、散点图与线性回归、带状图
- MySQL时间、时区、自动填充0的问题
猜你喜欢

Redis based distributed ID generator

ESP8266连接onenet(旧版MQTT方式)

Unity3d, Alibaba cloud server, platform configuration

基於Redis的分布式ID生成器

Single chip Bluetooth wireless burning

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

Types de variables JS et transformations de type communes

Guided package method in idea
![[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree](/img/6e/0802a92511ac50a652afa1678ad28c.jpg)
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree

Basic operations of databases and tables ----- classification of data
随机推荐
[offer78] merge multiple ordered linked lists
Expected value (EV)
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
Unity3d, Alibaba cloud server, platform configuration
MySQL占用内存过大解决方案
JS regular expression basic knowledge learning
Symbolic representation of functions in deep learning papers
(一)R语言入门指南——数据分析的第一步
Basic operations of databases and tables ----- classification of data
[offer18] delete the node of the linked list
Pat 1097 duplication on a linked list (25 points)
[offer9]用两个栈实现队列
(5) Introduction to R language bioinformatics -- ORF and sequence analysis
Common DOS commands
Redis based distributed ID generator
Esp8266 connect onenet (old mqtt mode)
[899]有序队列
程序设计大作业:教务管理系统(C语言)
单片机蓝牙无线烧录
Unity3D制作注册登录界面,并实现场景跳转