UGUI—自定义几何形状

作者:追风剑情 发布于:2019-10-11 17:18 分类:Unity3d

示例:

11111.png

MyGeometry.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.Rendering;

public class MyGeometry : MaskableGraphic
{
    // 自定义几何形状顶点
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        var color32 = color;
        vh.AddVert(new Vector3(0, 0), color32, new Vector2(0, 0));
        vh.AddVert(new Vector3(0, 100), color32, new Vector2(0, 1));
        vh.AddVert(new Vector3(100, 100), color32, new Vector2(1, 1));
        vh.AddVert(new Vector3(100, 0), color32, new Vector2(1, 0));
        vh.AddVert(new Vector3(50, -50), color32, new Vector2(1, 0));

        vh.AddTriangle(0, 1, 2);
        vh.AddTriangle(2, 3, 0);
        vh.AddTriangle(0, 3, 4);
    }
}

效果
222.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号   sitemap

川公网安备 51019002001593号