BaseMeshEffect
文章来源:https://www.toymoban.com/news/detail-511187.html
- 在UGUI中,这个修改的顶点单位是实际的像素(比如画布引用分辨率为800x600)
- 坐标系以Pivot 为原点(0,0)的坐标系,比如你的三角型顶点都在一象限,那么0.5的Pivot 效果就和其他的Image 0.0 的效果一样。
简易线条实现
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
//[ExecuteInEditMode]
public class Line : BaseMeshEffect
{
public Vector3[] quad = new Vector3[4];
public Vector2 StartPos = Vector2.zero;
public Vector2 EndPos = Vector2.one;
public float LineWidth = 1;
public override void ModifyMesh(VertexHelper vh)
{
vh.Clear();
DrawLine(vh,StartPos,EndPos,LineWidth);
}
// Update is called once per frame
void Update()
{
var image = MyImage;
if (image != null) {
image.SetVerticesDirty();
}
}
private Image curImage;
protected Image MyImage
{
get {
if (curImage == null) {
curImage = GetComponent<Image>();
}
return curImage;
}
}
private void DrawLine(VertexHelper vh, Vector2 startPos,Vector2 endPos,float width) {
var lineOri = endPos - startPos;
var verticalOri = GetVerticalFrom(lineOri).normalized;
var pos1 = endPos + (verticalOri * width);
var pos2 = endPos - (verticalOri * width);
var pos3 = startPos + (verticalOri * width);
var pos4 = startPos - (verticalOri * width);
vh.AddVert(pos1,Color.white,Vector4.zero);
vh.AddVert(pos2, Color.white,Vector4.zero);
vh.AddVert(pos3, Color.white,Vector4.zero);
vh.AddVert(pos4, Color.white,Vector4.zero);
vh.AddTriangle(0, 1, 2);
vh.AddTriangle(2, 1, 3);
}
private Vector2 GetVerticalFrom(Vector2 from) {
return new Vector2(-from.y,from.x);
}
}
参考
在Unity中绘制UGUI曲线图
在Unity Graph绘制文章来源地址https://www.toymoban.com/news/detail-511187.html
到了这里,关于Unity-UGUI-曲线绘制的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!