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

边栏推荐
- Expected value (EV)
- 基于Redis的分布式锁 以及 超详细的改进思路
- [899] ordered queue
- (the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
- Office提示您的许可证不是正版弹框解决
- Teach you to release a DeNO module hand in hand
- [Nodejs] 20. Koa2 onion ring model ----- code demonstration
- ES6 grammar summary -- Part I (basic)
- JS数组常用方法的分类、理解和运用
- 2021.11.10 compilation examination
猜你喜欢

MySQL時間、時區、自動填充0的問題

(1) Introduction Guide to R language - the first step of data analysis

Lock wait timeout exceeded try restarting transaction

Pytorch: tensor operation (I) contiguous

2021.11.10 compilation examination

Force buckle 1189 Maximum number of "balloons"

(四)R语言的数据可视化——矩阵图、柱状图、饼图、散点图与线性回归、带状图

Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0

(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析

Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
随机推荐
Common DOS commands
Important methods of array and string
Database course design: college educational administration management system (including code)
Detailed explanation of truncate usage
编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
[leetcode19] delete the penultimate node in the linked list
@The difference between Autowired and @resource
FairyGUI人物状态弹窗
JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
MySQL error warning: a long semaphore wait
idea中导包方法
关于Gateway中使用@Controller的问题
Types de variables JS et transformations de type communes
Générateur d'identification distribué basé sur redis
MySQL time, time zone, auto fill 0
Esp8266 connect onenet (old mqtt mode)
Redis cache update strategy, cache penetration, avalanche, breakdown problems
基於Redis的分布式ID生成器
Naive Bayesian theory derivation
Common properties of location