- Home /
How to manipulate vertices of the Rect Transform ?
Hi everyone,
So i was wondering if it is possible to manipulate vertices of Rect Transform, by code, to go from picture A to B or C. Or if it's possible in another way to deform an image?
Thank you very much in advance.
Do you just want to draw something with that shape? $$anonymous$$ost people just make one using the $$anonymous$$esh class.
Or what you have requires a RectTransform component? I feel like those are required to be Rectangles (so all 90-degree corners.)
Hi, you can modify the vertices of a UI Graphic component (position, color, UV....). This is not a modification of the RectTransform itself but may be enough. This is explained in documentation. Look for the Graphic class of UnityEngine.UI: http://docs.unity3d.com/ScriptReference/UI.Graphic.html
Answer by maxoja · Sep 10, 2018 at 06:55 PM
You can manipulate vertices of a UI component by using inheritance and override OnPopulateMesh
public class ReshapeImage : Image
{
protected override void OnPopulateMesh(VertexHelper vh)
{
base.OnPopulateMesh(vh);
for (int i = 0; i < vh.currentVertCount; i++)
{
UIVertex vert = UIVertex.simpleVert;
vh.PopulateUIVertex(ref vert, i);
Vector3 position = vert.position;
//
//manipulate position
//
vert.position = position;
vh.SetUIVertex(vert, i);
}
}
}
Your answer
Follow this Question
Related Questions
How to get size of dynamically created layout element 0 Answers
Setting values of a Transform childed to a RectTransform giving unexpected results. 1 Answer
Animate RectTransform anchoredPosition relatively to other RectTransform 0 Answers
Convert local point in RectTransform to screen space 2 Answers