有时候需要在播放粒子特效前就清楚的知道粒子特效将播放多久。查了一下Unity的API发现ParticleSystem的duaration属性真的好坑爹,因为不准。。。 不信你可以试试。
下面说计算特效时长的方法。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
static
float
ParticleSystemLength
(
Transform
transform
)
{
ParticleSystem
[
]
particleSystems
=
transform
.
GetComponentsInChildren
<
ParticleSystem
>
(
)
;
float
maxDuration
=
0
;
foreach
(
ParticleSystem
ps
in
particleSystems
)
{
if
(
ps
.
enableEmission
)
{
if
(
ps
.
loop
)
{
return
-
1f
;
}
float
dunration
=
0f
;
if
(
ps
.
emissionRate
<=
0
)
{
dunration
=
ps
.
startDelay
+
ps
.
startLifetime
;
}
else
{
dunration
=
ps
.
startDelay
+
Mathf
.
Max
(
ps
.
duration
,
ps
.
startLifetime
)
;
}
if
(
dunration
>
maxDuration
)
{
maxDuration
=
dunration
;
}
}
}
return
maxDuration
;
}
|
OK 这就算出来。 欢迎大家在下面留言,一起讨论开发技巧~嘿嘿。
- 本文固定链接: http://www.xuanyusong.com/archives/3512
- 转载请注明: 雨松MOMO 2015年05月29日 于 雨松MOMO程序研究院 发表