Unity 使用this关键字进行函数拓展 - LineRenderer
【摘要】
Example:
var lineRenderer = GetComponent<LineRenderer>();
lineRenderer
.SetStartColor(Color.red)
.SetEndColor(Color.red)
.SetStartWidth(0.1f)
.Set...
Example:
var lineRenderer = GetComponent<LineRenderer>();
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
{
/// <summary>
/// 光线渲染器相关拓展
/// </summary>
public static class LineRenderExtension
{
/// <summary>
/// 设置起始宽度
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="width">起始宽度</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetStartWidth(this LineRenderer self, float width)
{
self.startWidth = width;
return self;
}
/// <summary>
/// 设置结束宽度
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="width">结束宽度</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetEndWidth(this LineRenderer self, float width)
{
self.endWidth = width;
return self;
}
/// <summary>
/// 设置起始颜色
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="color">起始颜色</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetStartColor(this LineRenderer self, Color color)
{
self.startColor = color;
return self;
}
/// <summary>
/// 设置结束颜色
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="color">结束颜色</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetEndColor(this LineRenderer self, Color color)
{
self.endColor = color;
return self;
}
/// <summary>
/// 设置点个数
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="count">点个数</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetPositionCount(this LineRenderer self, int count)
{
self.positionCount = count;
return self;
}
/// <summary>
/// 设置点位置
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="index">索引</param>
/// <param name="position">位置</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetLinePosition(this LineRenderer self, int index, Vector3 position)
{
self.SetPosition(index, position);
return self;
}
/// <summary>
/// 设置是否循环(终点是否连接起点)
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="loop">是否循环</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetLoop(this LineRenderer self, bool loop)
{
self.loop = loop;
return self;
}
/// <summary>
/// 设置CornerVertices属性
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="cornerVertices">conner vertices</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetCornerVertices(this LineRenderer self, int cornerVertices)
{
self.numCornerVertices = cornerVertices;
return self;
}
/// <summary>
/// 设置EndCapVertices属性
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="endCapVertices">end cap vertices</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetEndCapVertices(this LineRenderer self, int endCapVertices)
{
self.numCapVertices = endCapVertices;
return self;
}
/// <summary>
/// 设置Alignment属性
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="alignment">alignment</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetAlignment(this LineRenderer self, LineAlignment alignment)
{
self.alignment = alignment;
return self;
}
/// <summary>
/// 设置TextureMode
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="textureMode">texture mode</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetTextureMode(this LineRenderer self, LineTextureMode textureMode)
{
self.textureMode = textureMode;
return self;
}
/// <summary>
/// 设置材质球
/// </summary>
/// <param name="self">光线渲染器</param>
/// <param name="material">材质球</param>
/// <returns>光线渲染器</returns>
public static LineRenderer SetMaterial(this LineRenderer self, Material material)
{
self.material = material;
return self;
}
}
}
文章来源: coderz.blog.csdn.net,作者:CoderZ1010,版权归原作者所有,如需转载,请联系作者。
原文链接:coderz.blog.csdn.net/article/details/116753909
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)