当前位置:网站首页>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);
});
}
}
三、最终运行效果
边栏推荐
- Important methods of array and string
- Office提示您的许可证不是正版弹框解决
- MySQL占用内存过大解决方案
- HCIP Day 12
- 1081 rational sum (20 points) points add up to total points
- Minio文件下载问题——inputstream:closed
- Unity3d camera, the keyboard controls the front and rear left and right up and down movement, and the mouse controls the rotation, zoom in and out
- idea问题记录
- JS Title: input array, exchange the largest with the first element, exchange the smallest with the last element, and output array.
- Gravure sans fil Bluetooth sur micro - ordinateur à puce unique
猜你喜欢
Pat 1097 duplication on a linked list (25 points)
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
Working principle of genius telephone watch Z3
Teach you to release a DeNO module hand in hand
NRF24L01故障排查
Unity3D制作注册登录界面,并实现场景跳转
Navigator object (determine browser type)
Unity场景跳转及退出
Unity3D,阿里云服务器,平台配置
JS数组常用方法的分类、理解和运用
随机推荐
[Red Treasure Book Notes simplified version] Chapter 12 BOM
[offer9]用两个栈实现队列
Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED
(the first set of course design) 1-4 message passing interface (100 points) (simulation: thread)
[leetcode15] sum of three numbers
idea问题记录
Common DOS commands
(1) Introduction Guide to R language - the first step of data analysis
Talking about the startup of Oracle Database
[899]有序队列
MySQL performance tuning - dirty page refresh
SSD technical features
Walk into WPF's drawing Bing Dwen Dwen
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
PT OSC deadlock analysis
Solution to the problem of automatic login in Yanshan University Campus Network
Office prompts that your license is not genuine pop-up box solution
[leetcode19]删除链表中倒数第n个结点
Minio文件下载问题——inputstream:closed