当前位置:网站首页>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);
});
}
}
三、最终运行效果
边栏推荐
- PT OSC deadlock analysis
- Office提示您的许可证不是正版弹框解决
- Working principle of genius telephone watch Z3
- JS變量類型以及常用類型轉換
- Special palindromes of daily practice of Blue Bridge Cup
- [offer29] sorted circular linked list
- (4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
- Arduino uno R3 register writing method (1) -- pin level state change
- MySQL takes up too much memory solution
- Meanings and differences of PV, UV, IP, VV, CV
猜你喜欢
Unity3D基础入门之粒子系统(属性介绍+火焰粒子系统案例制作)
MySQL占用内存过大解决方案
Latex learning
單片機藍牙無線燒錄
2021.11.10汇编考试
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
Unity场景跳转及退出
Basic operations of databases and tables ----- modifying data tables
Walk into WPF's drawing Bing Dwen Dwen
程序设计大作业:教务管理系统(C语言)
随机推荐
Pytorch: tensor operation (I) contiguous
Who says that PT online schema change does not lock the table, or deadlock
Get the position of the nth occurrence of the string
Whistle+switchyomega configure web proxy
Theoretical derivation of support vector machine
Arduino get random number
基於Redis的分布式ID生成器
基于Redis的分布式锁 以及 超详细的改进思路
如何给Arduino项目添加音乐播放功能
HCIP Day 12
History object
(the first set of course design) sub task 1-5 317 (100 points) (dijkstra: heavy edge self loop)
Latex learning
ES6 grammar summary -- Part 2 (advanced part es6~es11)
What is the maximum length of MySQL varchar field
[leetcode19]删除链表中倒数第n个结点
JS function promotion and declaration promotion of VaR variable
JS regular expression basic knowledge learning
JS 函数提升和var变量的声明提升
(5) Introduction to R language bioinformatics -- ORF and sequence analysis