I have some Graphic elements inside a Scroll Rect with Rect Mask 2D.
The clipping works well with all the native UI elements, but the ones that I have a custom shape, aren’t clipping at all.
Is there an easy way to get custom Graphic to clip?
Here’s an example of what I want to clip:
[ExecuteInEditMode]
public class UIButtonShape : Graphic
{
protected override void OnPopulateMesh(Mesh toFill)
{
// Aux
float w = rectTransform.rect.width;
float h = rectTransform.rect.height;
Vector2 cornerBL = new Vector2((0.0f - rectTransform.pivot.x) * w, (0.0f - rectTransform.pivot.y) * h); // Bottom Left
Vector2 cornerTR = new Vector2((1.0f - rectTransform.pivot.x) * w, (1.0f - rectTransform.pivot.y) * h); // Top Right
toFill.Clear();
var vbo = new VertexHelper(toFill);
UIVertex[] verts = new UIVertex[4];
// Bottom Left
UIVertex vert = UIVertex.simpleVert;
vert.position = cornerBL;
vert.color = color;
verts[0] = vert;
// Top Left
vert.position = new Vector2(cornerBL.x + h, cornerTR.y);
vert.color = color;
verts[1] = vert;
// Top Right
vert.position = new Vector2(cornerTR.x, cornerTR.y);
vert.color = color;
verts[2] = vert;
// Bottom Right
vert.position = new Vector2(cornerTR.x - h, cornerBL.y);
vert.color = color;
verts[3] = vert;
vbo.AddUIVertexQuad(verts);
vbo.FillMesh(toFill);
}
}
Appreciate any help with this.
Thanks
