线渲染器 (Line Renderer) 组件采用 3D 空间中两个或多个点的数组,在每个点之间绘制一条直线。因此,单个线渲染器组件可用于绘制从简单直线到复杂螺旋线的任何线条。这条线始终是连续的;如果需要绘制两条或更多完全独立的线,则应使用多个游戏对象,每个游戏对象都要有自己的线渲染器。
线渲染器不渲染一个像素宽的线。此渲染器将渲染宽度采用世界单位且可纹理化的公告牌线(总是面向摄像机的多边形)。线渲染器使用与轨迹渲染器 (Trail Renderer) 相同的线渲染算法。
属性 | 功能 |
---|---|
Cast Shadows | 确定线是否投射阴影,是应从线的一侧还是两侧投射阴影,或线是否应仅投射阴影而不以其他方式进行绘制。请参阅脚本 API 参考文档中的 Renderer.shadowCastingMode 以了解更多信息。 |
Receive Shadows | 如果启用此属性,线将接受阴影。 |
Motion Vectors | 选择要用于此线渲染器的运动矢量 (Motion Vector) 类型。请参阅脚本 API 参考文档中的 Renderer.motionVectorGenerationMode 以了解更多信息。 |
Materials | 这些属性描述了用于渲染线的材质数组。对于数组中的每种材质,该线将被绘制一次。 |
Light Parameters | 在此处引用光照贴图参数 (Lightmap Parameters) 资源以使线与全局光照系统交互。 |
Positions | 这些属性描述了要连接的 Vector3 点数组。 |
Use World Space | 如果启用此属性,这些点将视为世界空间坐标,而不受此组件附加到的游戏对象的变换所影响。 |
Loop | 启用此属性可连接线的第一个和最后一个位置。这样会形成闭环。 |
Width | 定义宽度值和曲线以控制线在其开始和结束之间的各个点处的宽度。曲线仅在每个顶点处采样,因此其精度受到线中存在的顶点数量的限制。线的总宽度由宽度值控制。 |
Color | 定义一个渐变来控制线沿其长度的颜色。 |
Corner Vertices | 此属性指示在绘制线中的角时使用多少个额外顶点。增加此值可使线的角显得更圆。 |
End Cap Vertices | 此属性指示使用多少个额外顶点在线上创建端盖。增加此值可使线的端盖显得更圆。 |
Alignment | 设置为 View 可使线面向摄像机,或设置为 Local 根据线的变换组件的方向对齐。 |
Texture Mode | 控制如何将纹理应用于线。使用 Stretch 可沿着线的整个长度应用纹理贴图,或使用 Wrap 使纹理沿着线的长度重复。应使用材质 (Material) 中的 Tiling 参数来控制重复率。 |
Shadow Bias | 沿着光照方向移动阴影以消除因使用公告牌几何体来模拟体积而导致的阴影瑕疵。 |
Generate Lighting Data | 如果启用此属性(选中复选框),则在构建线几何体时包含法线和切线。这样允许它使用具有场景光照的材质,例如通过标准着色器,或通过使用自定义着色器。 |
Sorting Layer | 渲染器排序图层的名称。 |
Order in Layer | 此渲染器在排序图层中的顺序。 |
Light Probes | 基于探针的光照插值模式。 |
Reflection Probes | 如果启用此属性,并且场景中存在反射探针,则会为此线渲染器拾取反射纹理,并将此纹理设置为内置的着色器 uniform 变量。 |
要创建线渲染器,请执行以下操作:
2017–05–31 页面已修订并进行了编辑审查
在 Unity 2017.1 中添加了一些属性 NewIn20171
在 Unity 2018.3 中向 Line Renderer 添加了 Shadow Bias 属性 NewIn20183
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.