Version: 2022.3
Line Renderer component
Billboard Renderer component

Trail Renderer component

Trail Renderer 组件在移动的游戏对象后面随着时间的推移渲染一条多边形轨迹。此组件可用于强调移动对象的运动感,或突出移动对象的路径或位置。

Trail Renderer 使用与 Line Renderer 相同的轨迹渲染算法。

准备开始

要创建轨迹渲染器,请执行以下操作:

  1. 在 Unity 菜单栏中,选择 GameObject > Effects > Trail
  2. 选择 Trail Renderer 游戏对象,并将其作为要生成轨迹的游戏对象的父项。
  3. 使用 Inspector 窗口配置轨迹的颜色、宽度和其他显示设置。
  4. 通过移动游戏对象并在 Scene 视图中观察效果,可在编辑模式下预览轨迹。
示例 Trail Renderer 配置和生成的轨迹。
示例 Trail Renderer 配置和生成的轨迹。

轨迹渲染器材质

默认情况下,轨迹渲染器 (Trail Renderer) 使用内置材质 Default-Line。您可以更改轨迹的外观而无需更改此材质,例如编辑轨迹的颜色渐变或宽度。

对于其他效果,例如在轨迹上应用纹理,需要使用其他材质。如果您不想为新材质编写自己的着色器,可以将 Unity 内置的标准粒子着色器与轨迹渲染器结合使用。如果将纹理应用到轨迹渲染器,则纹理应为正方形尺寸(例如 256x256 或 512x512)。

如果将多个材质应用于轨迹渲染器,则会为每个材质渲染一次。

请参阅创建和使用材质以了解更多信息。

点之间的距离

Min Vertex Distance 值可以确定在将新段添加到该路径之前,应用轨迹的游戏对象必须行进的距离(采用世界单位)。像 0.1 这样较小的值会更频繁地创建轨迹段,从而形成更平滑的轨迹。像 1.5 这样较大的值会创建在外观上更有锯齿状的轨迹段。另外,当顶点非常靠近并且轨迹会在短距离内显著改变方向时,较宽的轨迹可能出现视觉瑕疵。

出于性能原因,最好使用尽可能最大的值来实现要创建的效果。

Trail Renderer Inspector reference

本节包含以下小节:

轨迹设置

属性 功能
Width 定义宽度值和曲线值以控制轨迹沿其长度的宽度。

曲线是在每个顶点处采样的,因此其精度受制于轨迹中的顶点数量。轨迹的总宽度由宽度值控制。
Time 定义轨迹中某个点的生命周期(以秒为单位)。
Min Vertex Distance 轨迹中两点之间的最小距离(采用世界单位)。
AutoDestruct 启用此属性可在附加到 Trail Renderer 组件的游戏对象静止 Time 秒之后销毁该游戏对象。
Emitting 启用此属性后,Unity 会在轨迹中添加新点。禁用此属性后,Unity 不会向轨迹中添加新点。使用此属性可暂停和恢复轨迹生成功能。
Color 定义一个渐变来控制轨迹沿其长度的颜色。

Unity 在每个顶点处从颜色渐变 (Color Gradient) 中采样颜色。在每个顶点之间,Unity 对颜色应用线性插值。向轨迹添加更多顶点可能会更接近详细的渐变。
Corner Vertices 此属性指示在绘制轨迹中的角时使用多少个额外顶点。增加此值可使轨迹的角显得更圆。
End Cap Vertices 此属性指示使用多少个额外顶点在轨迹上创建端盖。增加此值可使轨迹的端盖显得更圆。
Alignment 设置轨迹面向的方向。
View 轨迹面向摄像机。
TransformZ 轨迹朝向其变换组件的 Z 轴。
Texture Mode 控制如何将纹理应用于轨迹。
Stretch 沿轨迹的整个长度映射纹理一次。
Tile 基于轨迹长度(采用世界单位)沿轨迹重复纹理。要设置平铺率,请使用 Material.SetTextureScale
DistributePerSegment 沿轨迹的整个长度映射纹理一次(假设所有顶点均匀分布)。
RepeatPerSegment 沿轨迹重复纹理(每个轨迹段重复一次)。要调整平铺率,请使用 Material.SetTextureScale
Shadow Bias 设置沿着光照方向的阴影移动量以消除阴影瑕疵。
Generate Lighting Data 如果启用此属性,Unity 在构建轨迹几何体时包含法线和切线。这样,轨迹几何体就可以使用采用了场景光照的材质。

材质

Materials 部分列出了此组件使用的所有材质

属性 描述
Size The number of elements in the material list.

If you decrease the number of elements, Unity deletes the elements at the end of the list. If you increase the number of elements, Unity adds new elements to the end of the list. Unity populates new elements with the same material that the element at the end of the list uses.
Element The materials in the list. You can assign a material asset to each element.

By default, Unity orders the list alphabetically based on the name of the materials. This list is reorderable, and Unity updates the number of the elements automatically as you change their order.

光照

Lighting 部分包含与光照相关的属性。

属性 描述
Cast Shadows Specify if and how this Renderer casts shadows when a suitable Light shines on it.

This property corresponds to the Renderer.shadowCastingMode API.
On This Renderer casts a shadow when a shadow-casting Light shines on it.
Off This Renderer does not cast shadows.
Two-sided This Renderer casts two-sided shadows. This means that single-sided objects like a plane or a quad can cast shadows, even if the light source is behind the mesh.

For Baked Global Illumination or Enlighten Realtime Global Illumination to support two-sided shadows, the material must support Double Sided Global Illumination.
Shadows Only This Renderer casts shadows, but the Renderer itself isn’t visible.
Receive Shadows Specify if Unity displays shadows cast onto this Renderer.

This property only has an effect if you enable Baked Global Illumination or Enlighten Realtime Global Illumination for this scene.

This property corresponds to the Renderer.receiveShadows API.
Contribute Global Illumination Include this Renderer in global illumination calculations, which take place at bake time.

This property only has an effect if you enable Baked Global Illumination or Enlighten Realtime Global Illumination for this scene.

Enabling this property enables the Contribute GI flag in the GameObject’s Static Editor Flags. It corresponds to the StaticEditorFlags.ContributeGI API.
Receive Global Illumination Whether Unity provides global illumination data to this Renderer from baked lightmaps, or from runtime Light Probes.

This property is only editable if you enable Contribute Global Illumination. It only has an effect if you enable Baked Global Illumination or Enlighten Realtime Global Illumination for this scene.

This property corresponds to the MeshRenderer.receiveGI API.
Lightmaps Unity provides global illumination data to this Renderer from lightmaps.
Light Probes Unity provides global illumination data to this Renderer from Light Probes in the scene.
Prioritize Illumination Enable this property to always include this Renderer in Enlighten Realtime Global Illumination calculations. This ensures that the Renderer is affected by distant emissives, even those which are normally excluded from Global Illumination calculations for performance reasons.

This property is visible only if Contribute GI is enabled in the GameObject’s Static Editor Flags, your project uses the Built-in Render Pipeline, and Enlighten Realtime Global Illumination is enabled in your scene.

Probes

Probes 部分包含与光照探针反射探针有关的属性。

属性 描述
Light Probes Set how this Renderer receives light from the Light Probes system.

This property corresponds to the Renderer.lightProbeUsage API.
Off The Renderer doesn’t use any interpolated Light Probes.
Blend Probes The Renderer uses one interpolated Light Probe. This is the default value.
Use Proxy Volume The Renderer uses a 3D grid of interpolated Light Probes.
Custom Provided The Renderer extracts Light Probe shader uniform values from the MaterialPropertyBlock.
Proxy Volume Override Set a reference to another GameObject that has a Light Probe Proxy Volume component.

This property is only visible when Light Probes is set to Use Proxy Volume.
Reflection Probes Set how the Renderer receives reflections from the Reflection Probe system.

This property corresponds to the Renderer.probeAnchor API.
Off Disables Reflection Probes. Unity uses a skybox for reflection.
Blend Probes Enables Reflection Probes. Blending occurs only between Reflection Probes. This is useful in indoor environments where the character may transition between areas with different lighting settings.
Blend Probes and Skybox Enables Reflection Probes. Blending occurs between Reflection Probes, or between Reflection Probes and the default reflection. This is useful for outdoor environments.
Simple Enables Reflection Probes, but no blending occurs between Reflection Probes when there are two overlapping volumes.
Anchor Override Set the Transform that Unity uses to determine the interpolation position when using the Light Probe or Reflection Probe systems. By default, this is the centre of the bounding box of the Renderer’s geometry.

This property corresponds to the Renderer.probeAnchor API.

Additional Settings

Additional Settings 部分包含额外的属性。

Property Description
Motion Vectors Set whether to use motion vectors to track this Renderer’s per-pixel, screen-space motion from one frame to the next. You can use this information to apply post-processing effects such as motion blur.

Note: not all platforms support motion vectors. See SystemInfo.supportsMotionVectors for more information.

This property corresponds to the Renderer.motionVectorGenerationMode API.
Camera Motion Only Use only Camera movement to track motion.
Per Object Motion Use a specific pass to track motion for this Renderer.
Force No Motion Do not track motion.
Dynamic Occlusion When Dynamic Occlusion is enabled, Unity’s occlusion culling system culls this Renderer when it is blocked from a Camera’s view by a Static Occluder. Otherwise, the system does not cull this Renderer when it is blocked from a Camera’s view by a Static Occluder.

Dynamic Occlusion is enabled by default. Disable it for effects such as drawing the outline of a character behind a wall.
Sorting Layer The name of this Renderer’s Sorting Layer.
Order in Layer This Renderer’s order within a Sorting Layer.

TrailRenderer

Line Renderer component
Billboard Renderer component