什么是粒子系统?
粒子系统操作方法

在 Unity 中使用粒子系统

Unity 使用组件实现粒子系统,因此将粒子系统放置在场景中涉及到添加预制的游戏对象(菜单:__GameObject__ > Effects > Particle System__)或将组件添加到现有游戏对象(菜单:__Component > Effects > Particle System__)。由于组件非常复杂,因此 Inspector 分为多个可折叠子部分或__模块__,每个子部分或模块都包含一组相关属性。此外,可使用单独的 Editor 窗口(通过 Inspector 中的 Open Window__ 按钮访问)同时编辑一个或多个系统。请参阅有关粒子系统组件和各个粒子系统模块的文档,了解更多信息。

选择带有粒子系统的游戏对象时,Scene 视图包含一个小的 Particle Effect 面板,其中有一些简单控件,用于显示对系统设置的更改。

Playback Speed 用于加快或减慢粒子模拟速度,可以直观查看在高级状态下的效果。Playback Time 表示自系统启动以来经过的时间;这可能比实时更快或更慢,具体取决于播放速度。Particle Count 表示系统中当前有多少粒子。通过单击 Playback Time 标签并向左和向右拖动鼠标,即可前后移动播放时间。面板顶部的按钮可用于暂停和恢复模拟,或停止模拟并重置为初始状态。

随时间推移而变化的属性

粒子甚至整个粒子系统的许多数字属性都可能随时间而变化。Unity 提供了几种不同的方法来指定这种变化的发生方式:

  • __Constant:__属性的值在其整个生命周期内是固定的。
  • __Curve:__该值由曲线/图形指定。
  • __Random Between Two Constants:__两个常量值定义了值的上限和下限;实际值随着时间的推移在这些边界之间随机变化。
  • Random Between Two Curves: Two curves define the upper and lower bounds of the value at a given point in its lifetime; the current value varies randomly between those bounds.

When you set a property to Curve or Random Between Two Curves, the Particle System Curves editor appears at the bottom of the Inspector:

To edit a curve, click and drag an end point or key to reshape the curve:

Particle System curves are similar to Animation curves. For information on using curves, see the documentation on Editing Curves.

The Particle System Curves editor has the following buttons:

  • Optimize: Fits the curve into four or fewer keys to build a fast evaluator called a Polynomial, which is more efficient than reading the unoptimized curve.
  • Remove: Deletes the selected curve.

To edit the way in which the Particle System plays curves, click the cog next to a selected key and choose one of the following options:

  • Loop: Plays the curve the specified number times over a particle’s life. For example, if you make a curve that scales a particle’s size up and down, you can tell it to loop multiple times, which causes the “up and down” animation to happen multiple times before the particle dies, instead of just once.
  • Ping Pong: Similar to Loop, but plays the curve forwards then backwards in a continuous oscillation.
  • Clamp: Limits particle queries that fall outside the curve time range to the first or last value of the curve.

The Start Color property in the main module has the following options:

  • Color: All particles start with this color throughout the lifetime of the Particle System. Particles can still change color during their lifetime.
  • Gradient: The Particle System emits particles which start with the colour at the beginning of the gradient, and end at the colour at the end of the gradient. The gradient line represents the lifetime of the Particle System; the Particle System picks a color from the gradient at the point corresponding to the current age of the Particle System.
  • Random Between Two Colors: The Particle System chooses a starting particle color from a random linear interpolation between the two given colors.
  • Random Between Two Gradients: The Particle System chooses a color from each of the given gradients at the point corresponding to the current age of the system. The starting particle color is chosen as a random linear interpolation between the two chosen colors.
  • Random Color: Similar to Gradient mode, where particles take their initial color from the defined Gradient. However, in this mode, the Particle System does not choose samples based on the age of the Particle System, but instead it selects them at random. This mode also works well with the Fixed Gradient Mode, which is inside the Gradient Editor. When enabled, you can select a predefined list of precise starting colors, and apply a probability to each color.

Other color properties, such as Color over Lifetime, can use the Gradient or Random Between Two Gradients modes.

To calculate the final particle color result, the Particle System multiplies color properties in various modules together per channel.

When you set the Gradient color for particles, the Gradient Editor appears:

  • Mode: Determines whether the particle color settings are blended or not.
  • Color: Displays the color of the currently selected key in the Gradient. Use this to edit the color at that position of the Gradient.
  • Location: Shows how far along on the Gradient the currently selected key is.
  • Presets: Allows you to save Gradient settings. Click New to make the current set of values a Gradient preset.

各种模块中的颜色属性按照每个通道相乘,从而计算出最终的粒子颜色结果。

动画绑定

动画系统可以访问所有粒子属性,这意味着可以将它们设置到关键帧中并从动画中控制它们。

要访问粒子系统的属性,必须有一个 Animator 组件连接到粒子系统的游戏对象。此外还需要动画控制器 (Animation Controller) 和动画。

要动画化粒子系统,请添加 Animator 组件,并为动画控制器 (Animator Controller) 分配动画。
要动画化粒子系统,请添加 Animator 组件,并为动画控制器 (Animator Controller) 分配动画。

要动画化粒子系统属性,请打开 Animation 窗口__,并选择包含 Animator 和粒子系统的游戏对象。单击 Add Property__ 以添加属性。

在 Animation 窗口中为动画添加属性。
在 Animation 窗口中为动画添加属性。

向右滚动以显示__添加控件__。

请注意,对于曲线,只能对整体__曲线乘数__进行关键帧设置(可在 Inspector 中的曲线编辑器旁边找到该曲线乘数)。


  • 2019–04–16 Page amended with limited editorial review

  • 在 Unity 4.6 中更改了 GameObject 菜单

  • Particle System loop/ping-pong curve playing added in 2018.3 NewIn20183

什么是粒子系统?
粒子系统操作方法