The effect

implementation

A character’s 3D attributes (strength, agility, intelligence) are not…

1. Define a class that extends from MaskableGraphic

    public class Triangle : MaskableGraphic.ICanvasRaycastFilter
Copy the code

2. Use your own Sprite for the center image

    [SerializeField] Sprite m_image;
    public override Texture mainTexture => m_image == null ? s_WhiteTexture : m_image.texture;
Copy the code

3, definitions,

    // Define three pos
    public Vector2 positionA;
    public Vector2 positionB;
    public Vector2 positionC;
    // Vertex information
    UIVertex[] m_vertexes = new UIVertex[3];
    // Array of three vertices
    Vector2[] m_uvs = new Vector2[3];
    protected override void Start()
    {
        // Triangle is drawn clockwise
        m_uvs[0] = new Vector2(0.0);
        m_uvs[1] = new Vector2(0.5 f.1);
        m_uvs[2] = new Vector2(1.0);
    }
Copy the code

4. Draw the OnPopulateMesh method again

    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();
        for (int i = 0; i < 3; i++)
        {
            m_vertexes[i].color = color;
            m_vertexes[i].uv0 = m_uvs[i];
        }

        m_vertexes[0].position = positionA;
        m_vertexes[1].position = positionB;
        m_vertexes[2].position = positionC;

        vh.AddVert(m_vertexes[0]);
        vh.AddVert(m_vertexes[1]);
        vh.AddVert(m_vertexes[2]);
        // The order of drawing
        vh.AddTriangle(0.1.2);
    }
Copy the code

Create a gameobject in the ugui, then use the CanvasRenderer component on top of it, and then add the c# script to draw.

    local triangle = self.view.image_hua:GetComponent("Triangle")
    [[the pos of this setting is still a little bit wrong, this needs to be multiplied by half of the size of the image to control the pos. And when drawing 0,0 is in the center of the gameobject, not in the lower left corner. I will study it tomorrow because I am going to leave work.]]
    triangle.positionB = CS.UnityEngine.Vector2(0,pos[1] *90)
    triangle.positionA = CS.UnityEngine.Vector2(-pos[2] *90,-pos[2] *90)
    triangle.positionC = CS.UnityEngine.Vector2(pos[3] *90,-pos[3] *90)

    triangle:SetVerticesDirty()
    --[contains the refresh method // which will re-execute OnPopulateMesh SetVerticesDirty() in the next frame; // Which will re-set material and Texture SetMaterialDirty() in the next frame; SetLayoutDirty();]]
Copy the code

Reference Documentation Link