Example:
var lineRenderer = GetComponent();
lineRenderer
.SetStartColor(Color.red)
.SetEndColor(Color.red)
.SetStartWidth(0.1f)
.SetEndWidth(0.1f)
.SetLinePosition(0, point1)
.SetLinePosition(1, point2)
.SetLoop(true)
.SetCornerVertices(90)
.SetEndCapVertices(90)
.SetAlignment(LineAlignment.View)
.SetTextureMode(LineTextureMode.Stretch);
Extension:
using UnityEngine;
namespace SK.Framework
{
///
/// 光线渲染器相关拓展
///
public static class LineRenderExtension
{
///
/// 设置起始宽度
///
/// 光线渲染器
/// 起始宽度
/// 光线渲染器
public static LineRenderer SetStartWidth(this LineRenderer self, float width)
{
self.startWidth = width;
return self;
}
///
/// 设置结束宽度
///
/// 光线渲染器
/// 结束宽度
/// 光线渲染器
public static LineRenderer SetEndWidth(this LineRenderer self, float width)
{
self.endWidth = width;
return self;
}
///
/// 设置起始颜色
///
/// 光线渲染器
/// 起始颜色
/// 光线渲染器
public static LineRenderer SetStartColor(this LineRenderer self, Color color)
{
self.startColor = color;
return self;
}
///
/// 设置结束颜色
///
/// 光线渲染器
/// 结束颜色
/// 光线渲染器
public static LineRenderer SetEndColor(this LineRenderer self, Color color)
{
self.endColor = color;
return self;
}
///
/// 设置点个数
///
/// 光线渲染器
/// 点个数
/// 光线渲染器
public static LineRenderer SetPositionCount(this LineRenderer self, int count)
{
self.positionCount = count;
return self;
}
///
/// 设置点位置
///
/// 光线渲染器
/// 索引
/// 位置
/// 光线渲染器
public static LineRenderer SetLinePosition(this LineRenderer self, int index, Vector3 position)
{
self.SetPosition(index, position);
return self;
}
///
/// 设置是否循环(终点是否连接起点)
///
/// 光线渲染器
/// 是否循环
/// 光线渲染器
public static LineRenderer SetLoop(this LineRenderer self, bool loop)
{
self.loop = loop;
return self;
}
///
/// 设置CornerVertices属性
///
/// 光线渲染器
/// conner vertices
/// 光线渲染器
public static LineRenderer SetCornerVertices(this LineRenderer self, int cornerVertices)
{
self.numCornerVertices = cornerVertices;
return self;
}
///
/// 设置EndCapVertices属性
///
/// 光线渲染器
/// end cap vertices
/// 光线渲染器
public static LineRenderer SetEndCapVertices(this LineRenderer self, int endCapVertices)
{
self.numCapVertices = endCapVertices;
return self;
}
///
/// 设置Alignment属性
///
/// 光线渲染器
/// alignment
/// 光线渲染器
public static LineRenderer SetAlignment(this LineRenderer self, LineAlignment alignment)
{
self.alignment = alignment;
return self;
}
///
/// 设置TextureMode
///
/// 光线渲染器
/// texture mode
/// 光线渲染器
public static LineRenderer SetTextureMode(this LineRenderer self, LineTextureMode textureMode)
{
self.textureMode = textureMode;
return self;
}
///
/// 设置材质球
///
/// 光线渲染器
/// 材质球
/// 光线渲染器
public static LineRenderer SetMaterial(this LineRenderer self, Material material)
{
self.material = material;
return self;
}
}
}