当前位置:网站首页>Unity3d:UGUI,UI与特效粒子层级,2018.2以上版本BakeMesh,粒子在两个Image之间且在ScrollView
Unity3d:UGUI,UI与特效粒子层级,2018.2以上版本BakeMesh,粒子在两个Image之间且在ScrollView
2022-07-23 05:45:00 【四夕立羽】
ui上面展示粒子一般来说有两种方案
1.通过rendertexture渲染,可以完美处理层级问题,不过性能不好,多个摄像机
2.直接放到ui界面调整特效sort in layer,不过如果ui特效穿插多,层级不好管理,且多canvas造成合批问题
现在来第三种方法粒子BakeMesh(要2018.2以上版本)
来自Github:https://github.com/mob-sakai/ParticleEffectForUGUI
优点:可像UGUI一样通过上下调整层级排序,接受Mask处理
各方案比较

粒子BakeMesh
原理:直接让粒子的网格和贴图在ui基础组件里面渲染
使用接口
ParticleSystemRenderer.BakeMesh和ParticleSystemRenderer.BakeTrailsMesh这里是生成网格信息
CanvasRenderer.SetMesh
CanvasRenderer.SetTexture
把mesh和texture扔给canvasRenderer渲染
代码解析
UIParticle
UIParticle 是粒子的父物体
[RequireComponent(typeof(RectTransform))]
[RequireComponent(typeof(CanvasRenderer))]
public class UIParticle : MaskableGraphic
{
protected override void OnEnable()
{
UIParticleUpdater.Register(this);
CanvasRenderer渲染包含在Canvas中的UI对象,是一个Graphic必须的
UIParticleUpdater
Canvas.willRenderCanvases监听
internal static class UIParticleUpdater
{
[RuntimeInitializeOnLoadMethod]
private static void InitializeOnLoad()
{
Canvas.willRenderCanvases -= Refresh;
Canvas.willRenderCanvases += Refresh;
}
Q: Canvas.willRenderCanvases监听
A:官方解释:在即将开始 Canvas 渲染前调用的事件。
这让您能够延时处理/更新基于画布的元素,直到即将开始渲染它们之时。在这里做生成粒子的Mesh,再通过调用particle.canvasRenderer.SetMesh,渲染粒子的mesh
Refresh
private static void Refresh(UIParticle particle)
{
Profiler.BeginSample("[UIParticle] Bake mesh");
BakeMesh(particle);
Profiler.EndSample();
Profiler.BeginSample("[UIParticle] Set mesh to CanvasRenderer");
particle.canvasRenderer.SetMesh(particle.bakedMesh);
Profiler.EndSample();
}

边栏推荐
- 动态规划——“换硬币问题”
- C language small project - student achievement management system
- [AUTOSAR com 3. signal sending and receiving process tx/rx]
- 前缀和 LeetCode2100. 适合打劫银行的日子
- Anonymous upper computer V7 waveform display
- Steel structure review questions
- [AUTOSAR com 1. introduction to communication protocol stack]
- Configure TX1 system + set to solid-state disk startup
- 剑指offer 05 两个栈实现队列
- 关于如何排查vpn服务器无法转发的问题
猜你喜欢
博客搭建三:评论系统选择

Blog Building II: next theme related settings beta

C语言数据库:基于tcp多进程的在线词典,有详细的步骤已经图解,欢迎大家来观看

C language small project - student achievement management system

Redis——配置及应用
![[AUTOSAR candrive 2. understand the mapping relationship between communication HOH, canid and pduid]](/img/6d/ae145053b5fc46b583e5892ca4a945.png)
[AUTOSAR candrive 2. understand the mapping relationship between communication HOH, canid and pduid]

Axure实现增删改查

C语言小项目——学生成绩管理系统

unity3d:向量计算,AOE图形相交

Review of basic principles of steel structure
随机推荐
博客搭建四:将自己的博客加入百度和谷歌收录的方法
Embedded from entry to mastery (buried) - sharing of ultra detailed knowledge points 1
Desktop remote protocol - codec
大白话说说synchronized关键词的三种用法
RPM build 已经安装了依赖包但还是报错没有包中提供的模块
C语言数据库:详细的说明用学生管理系统了解数据库的操作,简单易懂。
Blog building 4: how to add your blog to Baidu and Google
The CUDA version of pytorch installed by anconda is inconsistent with the CUDA version of the system
Redis——配置及应用
简单实现栈的功能
视频编解码相关资料汇总
C语言基础练习题初学者可参考
Anonymous upper computer V7 waveform display
Vs attribute configuration related knowledge
0回溯/动态规划中等 LeetCode526. 优美的排列
大小写字母转换
[AUTOSAR cantp 1. learn the network layer protocol of UDS diagnosis]
0动态规划 LeetCodde313. 超级丑数
二叉树的实现-c
[learning summary]