您的位置:首页 > 移动开发 > Unity3D

Unity3d学习笔记(一)Particle Layer

2014-01-08 16:47 232 查看
今天简单看了下一个比较老的Partical Tutorial的例子,感觉Unity的粒子系统还是较为先进的,以前GB连长条形粒子都做不到,真心痛苦……但GB可以直接在Max里面预览效果,而且可以使用Max本身的粒子系统和动画工具,这样的设计思路即使现在看来也是非常先进的,可惜换了下家之后一直不死不活……商业化的恶果,不提了。

废话说完,接下来记笔记:

在使用旧有的Legacy Particle System时,Particle Renderer的Materials Size参数可以设置成大于1使得同一个粒子系统使用多种材质,但是似乎排序是id越低的排在越后面,比如Element 0就排在Element 1的下面,这个和新的Shuriken粒子系统里面的Sorting Fudge正好反过来,后者是数字越低排在越前(这里的前后都是指在摄像机空间内的前后关系)

旧有的Legacy Particle System当多个粒子系统重合的时候,自动排序会变得混乱,这时候可以采用一个Particle Layer的强制排序脚本挂在物体上,是个javascript,不知道编译之后效率如何,代码如下:

// ParticleLayer.js

var layerhieght = 0.00;

private var position : Vector3;

position = transform.localPosition;

function Update ()

{

object = Camera.main.gameObject;

vector = object.transform.position - transform.position;

if(transform.parent && (vector.magnitude > layerhieght || layerhieght < 0.00) ) transform.position = transform.parent.TransformPoint(position) + vector.normalized * layerhieght;

}

To get the script into the project, click on the Create menu in the Project pane and select JavaScript from the
menu. Name your script "ParticleLayer" and then open it and paste the code into it. Save it, return to Unity and wait for it to compile. (Shown by a little rotating thing in the lower right corner. With just this script it should be almost instant) Once it
is done, drag the script from the Project pane to the Hierarchy and onto your fire particle emitter that is a child of "Fire Group". Then select the object you just dragged the script onto and set Layer Height to 0.5. This will make the fire always 0.5 meters
closer to the camera then it normally would be.
参数只要大于0估计就差不多了,不过对于烟雾和火焰的制作,烟雾和火焰发射器之间的间距肯定要大于这个数值,不然从顶上或者底下看起来就不对了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d