当前位置:网站首页>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);
});
}
}
三、最终运行效果

边栏推荐
- [Leetcode15]三数之和
- Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
- (三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
- FairyGUI简单背包的制作
- Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED
- What is the maximum length of MySQL varchar field
- idea中导包方法
- Esp8266 connect onenet (old mqtt mode)
- [offer18] delete the node of the linked list
- Talking about the startup of Oracle Database
猜你喜欢

Arduino JSON data information parsing

数据库课程设计:高校教务管理系统(含代码)

(core focus of software engineering review) Chapter V detailed design exercises

(一)R语言入门指南——数据分析的第一步

History object
![[Red Treasure Book Notes simplified version] Chapter 12 BOM](/img/ff/0ad410b5b556c0e16a4076a2a0577b.jpg)
[Red Treasure Book Notes simplified version] Chapter 12 BOM

NRF24L01故障排查

單片機藍牙無線燒錄

Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)

Vscode basic configuration
随机推荐
js 变量作用域和函数的学习笔记
單片機藍牙無線燒錄
idea中导包方法
2021.11.10汇编考试
JUC forkjoin and completable future
[Offer29] 排序的循环链表
Office prompts that your license is not genuine pop-up box solution
Esp8266 uses Arduino to connect Alibaba cloud Internet of things
[Red Treasure Book Notes simplified version] Chapter 12 BOM
(3) Introduction to bioinformatics of R language - function, data Frame, simple DNA reading and analysis
Page performance optimization of video scene
First use of dosbox
Types de variables JS et transformations de type communes
Unity scene jump and exit
2022.2.12 resumption
Unity3D摄像机,键盘控制前后左右上下移动,鼠标控制旋转、放缩
About using @controller in gateway
(五)R语言入门生物信息学——ORF和序列分析
Mysqldump error1066 error solution
Pat 1097 duplication on a linked list (25 points)