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

边栏推荐
- 基于Redis的分布式ID生成器
- HCIP Day 12
- Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
- 记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
- JUC forkjoin and completable future
- Symbolic representation of functions in deep learning papers
- [leetcode19]删除链表中倒数第n个结点
- Force buckle 1189 Maximum number of "balloons"
- [leetcode622] design circular queue
- Single chip Bluetooth wireless burning
猜你喜欢

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

JS regular expression basic knowledge learning

Arduino JSON data information parsing

ORA-02030: can only select from fixed tables/views
![Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]](/img/b0/176bf6dea2201afc892d6750c5974b.png)
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]

Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
![[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data](/img/28/221b0a51ef5f2e8ed5aeca2de8f463.jpg)
[Clickhouse kernel principle graphic explanation] about the collaborative work of partitioning, indexing, marking and compressed data

History object
![[Nodejs] 20. Koa2 onion ring model ----- code demonstration](/img/a8/a4390238685903b63bb036206f8dcb.jpg)
[Nodejs] 20. Koa2 onion ring model ----- code demonstration

Common properties of location
随机推荐
Minio文件下载问题——inputstream:closed
Compilation principle: preprocessing of source program and design and implementation of lexical analysis program (including code)
Whistle+switchyomega configure web proxy
CUDA C programming authoritative guide Grossman Chapter 4 global memory
dosbox第一次使用
Expected value (EV)
Basic operations of databases and tables ----- creating data tables
There is no red exclamation mark after SVN update
基於Redis的分布式ID生成器
Minio file download problem - inputstream:closed
Mysqldump error1066 error solution
(core focus of software engineering review) Chapter V detailed design exercises
关于Gateway中使用@Controller的问题
Particle system for introduction to unity3d Foundation (attribute introduction + case production of flame particle system)
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
Arduino gets the length of the array
MySQL占用内存过大解决方案
idea中导包方法
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
如何给Arduino项目添加音乐播放功能