Unity3d-Particle System 5.x系统的学习(四)
Unity3d-Particle System 5.x系统的学习(四)
今天,我们来聊聊unity5.x的粒子系统和unity4.x粒子系统的区别。
我大致看了下,区别还是蛮多的,但是总体的粒子制作思路一样,只不过添加了很多子模块方便我们制作出更加美观的粒子。
下面是总体的粒子系统组件:
红色边框划出的就是unity5.x新增的子模块。
ok,我们接下来分析每个模块的特征和参数:
External Forces:(风(wind zone)对粒子的影响)
从英文表面意思解析:就是外部的力。(风力就是外部力)
External Forces module
This property modifies the effect of wind zones on particles emitted by the system.
官方对他的解析是:此参数是影响风力对粒子发射的。
我做了个实验,就是在场景中添加Wind Zone组件,看他是否对粒子有影响:
实验证明确实如此,粒子会受到风力的影响,往风力的方向发射。当增加Multiplier的值,会加大风力对粒子影响的力度,那么偏的也就越大。
Noise:(噪声模块)
这个模块是采用噪声的算法来改变粒子的运动轨迹。下面来看看官方对他的特征描述:
Details
Adding noise to your particles is a simple and effective way to create interesting patterns and effects. For example, imagine how embers from a fire move around, or how smoke swirls as it moves. Strong, high frequency noise could be used to simulate the fire embers, while soft, low frequency noise would be better suited to modeling a smoke effect.
For maximum control over the noise, you can enable the Separate Axes option. This allows you to control the strength and remapping on each axis independently.
翻译来的意思就是:
向粒子添加噪声是创建有趣模式和效果的一种简单而有效的方法。例如,想象一下火中的余烬是如何移动的,或者烟雾在移动时是如何旋转的。强、高频噪声可以用来模拟火烬,而软、低频噪声更适合模拟烟雾效果。
说人话就是,噪声可以改变粒子运动轨迹,模拟余烬和烟雾,他们都有个特征就是螺旋上升。
我们来看下增加噪声模块和没有噪声的区别:
1.没有噪声:
2.有噪声
可以看到区别了吧,明显加了噪声的粒子十分暴动,呈现上下螺旋运动。非常符合我们火的余烬这种运动不规则的粒子。
Triggers:(触发器模块)
从第一个参数看,是要传入一个触发器。
然后下面是粒子和触发器不同的状态:
1.Inside(粒子在触发器里面)
2.Outside(粒子在触发器外面)
3.Enter(粒子进入触发器)
4.Exit(粒子退出触发器)
那么后面的选项是什么东西:
可以看到总共有三种:
1.Ignore:表示粒子不做任何处理。
2.Kill:表示粒子会消亡。
3.Callback:回到函数,我们需要代码添加。
ok,举个例子。比如粒子进入到这个触发器要销毁,那么我们在Enter后面选项选择Kill就行了。
Callback的使用方法:
我们具体来看看Callback怎么实现代码传入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class ParticleCallbackTest : MonoBehaviour { ParticleSystem ps; //粒子系统,这里和粒子区分开,一个是系统,一个是粒子 List<ParticleSystem.Particle> enter = new List<ParticleSystem.Particle>(); //进入触发器的粒子链表 List<ParticleSystem.Particle> exit = new List<ParticleSystem.Particle>(); //退出触发器的粒子链表 void Start() { ps = GetComponent<ParticleSystem>(); } private void OnParticleTrigger() { int numEnter = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter); int numExit = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit); //进入触发器的粒子改变颜色为红色 for ( int i = 0; i < numEnter; i++) { ParticleSystem.Particle p = enter[i]; p.startColor = new Color32(255, 0, 0, 255); enter[i] = p; } //退出触发器的粒子改变颜色为绿色 for ( int i = 0; i < numExit; i++) { ParticleSystem.Particle p = exit[i]; p.startColor = new Color32(0, 255, 0, 255); exit[i] = p; } //需要重新为粒子系统设置改版后的粒子 ps.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter); ps.SetTriggerParticles(ParticleSystemTriggerEventType.Exit, exit); } } |
可以看到粒子进入触发器变红,退出变绿,这都是代码控制的。
注意,在Enter和Exit必须选择Callback,否则是没有效果的哦。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单
· C# 13 中的新增功能实操
· Supergateway:MCP服务器的远程调试与集成工具
· Vue3封装支持Base64导出的电子签名组件