Version: 2021.3

ParticleSystem

class in UnityEngine

/

继承自:Component

切换到手册

描述

ParticleSystem 的脚本接口。功能强大、用途广泛的 Unity 粒子系统实现。

常规参数

粒子系统的常规参数保存在一个特殊的主模块中。在 Inspector 中,这些参数显示在所有其他模块上方:



在脚本中,可以通过 ParticleSystem.main 访问这些参数。

Accessing module properties

Particle System properties are grouped by the module they belong to, such as ParticleSystem.noise and ParticleSystem.emission. These properties are structs, but do not behave like normal C# structs. They are simply interfaces directly into the native code, so it is important to know how to use them, compared to a normal C# struct.

The key difference is that it is not necessary to assign the struct back to the Particle System component. When you set any property on a module struct, Unity immediately assigns that value to the Particle System.

Also, because each module is a struct, you must cache it in a local variable before you can assign any new values to the module. For example, instead of:
ParticleSystem.emission.enabled = true; // Doesn't compile
write:
var emission = ParticleSystem.emission; // Stores the module in a local variable
emission.enabled = true; // Applies the new value directly to the Particle System


模块效果乘数

每个模块都有一些特殊的乘数属性,利用这些属性,您可以在不编辑曲线本身的情况下更改曲线的整体效果。这些乘数属性全部以它们影响的曲线命名 - 例如,ParticleSystem.emission.rateMultiplier 控制 ParticleSystem.emission.rate 在给定系统中的整体效果。

常量值的简写表示法

对于简单的常量值,参数支持简写表示法。要为参数设置常量值,只需为其指定一个数字。无需在 ParticleSystemCurveMode.Constant 模式下创建 MinMaxCurveMinMaxGradient 对象。

For example, instead of:
var emission = ParticleSystem.emission;
emission.rate = new ParticleSystem.MinMaxCurve(5.0f);
write:
var emission = ParticleSystem.emission;
emission.rate = 5.0f;

性能注意事项:在粒子模块上设置属性时,设置会立即传递到本机代码。这样可以提供最佳的性能。也就是说,在模块结构上设置属性时,不会在脚本中设置需要重新设置回粒子系统的内容;一切都是自动完成的。

另请参阅:Particle

变量

collision粒子系统 CollisionModule 的脚本接口。
colorBySpeed粒子系统 ColorByLifetimeModule 的脚本接口。
colorOverLifetime粒子系统 ColorOverLifetimeModule 的脚本接口。
customData粒子系统 CustomDataModule 的脚本接口。
emission粒子系统 EmissionModule 的脚本接口。
externalForces粒子系统 ExternalForcesModule 的脚本接口。
forceOverLifetime粒子系统 ForceOverLifetimeModule 的脚本接口。
inheritVelocity粒子系统 InheritVelocityModule 的脚本接口。
isEmitting确定粒子系统是否发射粒子。当粒子系统的发射模块已完成、已暂停或已使用 Stop 和 StopEmitting 标志来停止该系统时,粒子系统可能停止发射。可以调用 Play 来恢复发射。
isPaused确定粒子系统是否已暂停。
isPlaying确定粒子系统是否在播放。
isStoppedDetermines whether the Particle System is in the stopped state.
lifetimeByEmitterSpeedScript interface for the Particle System Lifetime By Emitter Speed module.
lights粒子系统 LightsModule 的脚本接口。
limitVelocityOverLifetime粒子系统 LimitVelocityOverLifetimeModule 的脚本接口。.
main访问主粒子系统设置。
noise粒子系统 NoiseModule 的脚本接口。
particleCountThe current number of particles (Read Only). The number doesn't include particles of child Particle Systems
proceduralSimulationSupported该系统是否支持程序化模拟?
randomSeed重载用于粒子系统发射的随机种子。
rotationBySpeed粒子系统 RotationBySpeedModule 的脚本接口。
rotationOverLifetime粒子系统 RotationOverLifetimeModule 的脚本接口。
shape粒子系统 ShapeModule 的脚本接口。
sizeBySpeed粒子系统 SizeBySpeedModule 的脚本接口。
sizeOverLifetime粒子系统 SizeOverLifetimeModule 的脚本接口。
subEmitters粒子系统 SubEmittersModule 的脚本接口。
textureSheetAnimation粒子系统 TextureSheetAnimationModule 的脚本接口。
time播放位置(以秒为单位)。
trails粒子系统 TrailsModule 的脚本接口。
trigger粒子系统 TriggerModule 的脚本接口。
useAutoRandomSeed控制粒子系统是否使用自动生成的随机数作为随机数生成器的种子。
velocityOverLifetime粒子系统 VelocityOverLifetimeModule 的脚本接口。

公共函数

AllocateAxisOfRotationAttributeEnsures that the axisOfRotations particle attribute array is allocated.
AllocateCustomDataAttributeEnsures that the customData1 and customData2 particle attribute arrays are allocated.
AllocateMeshIndexAttributeEnsures that the meshIndices particle attribute array is allocated.
Clear删除粒子系统中的所有粒子。
Emit立即发射 count 个粒子。
GetCustomParticleData获取自定义每粒子数据流。
GetParticles获取该粒子系统的粒子。
GetPlaybackState返回与粒子系统的当前内部状态有关的所有数据。
GetTrails返回与粒子系统轨迹的当前内部状态有关的所有数据。
IsAlive粒子系统是否包含任何存活的粒子,还是会产生更多粒子?
Pause暂停系统,因此不再发射新粒子,也不再更新现有粒子。
Play启动粒子系统。
SetCustomParticleData设置自定义每粒子数据流。
SetParticles设置该粒子系统的粒子。
SetPlaybackState将此方法与先前调用 ParticleSystem.GetPlaybackState 的结果一起使用,以便将粒子系统恢复到存储在 playbackState 对象中的状态。
SetTrails将此方法与先前调用 ParticleSystem.GetTrails 的结果一起使用,以便将粒子系统恢复到存储在轨迹对象中的状态。
Simulate在给定时间段内模拟粒子以快进粒子系统,然后将其暂停。
Stop使用提供的停止行为,停止播放粒子系统。
TriggerSubEmitter在粒子系统的所有粒子上触发指定的子发射器。

静态函数

ResetPreMappedBufferMemory重置用于有效渲染粒子系统的保留图形内存的缓存。
SetMaximumPreMappedBufferCountsLimits the amount of graphics memory Unity reserves for efficient rendering of Particle Systems.

继承的成员

变量

gameObject此组件附加到的游戏对象。始终将组件附加到游戏对象。
tag此游戏对象的标签。
transform附加到此 GameObject 的 Transform。
hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

BroadcastMessage调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentReturns the component of type if the GameObject has one attached.
GetComponentInChildrenReturns the Component of type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the Component of type in the GameObject or any of its parents.
GetComponents返回 GameObject 中类型为 type 的所有组件。
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children using depth first search. Works recursively.
GetComponentsInParent返回 GameObject 或其任何父项中类型为 type 的所有组件。
SendMessage调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。
SendMessageUpwards调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。
TryGetComponent获取指定类型的组件(如果存在)。
GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindObjectOfType返回第一个类型为 type 的已加载的激活对象。
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。