Fixed editor handles for Relative size #Phew
parent
c4c6c81e80
commit
11309d2d82
|
@ -23,8 +23,25 @@ namespace UnityEngine.UI.Extensions
|
|||
//transform.pivot = Vector2.zero;
|
||||
Handles.matrix = transform.localToWorldMatrix;
|
||||
|
||||
var points = curveRenderer.Points;
|
||||
var sizeX = curveRenderer.rectTransform.rect.width;
|
||||
var sizeY = curveRenderer.rectTransform.rect.height;
|
||||
var offsetX = -curveRenderer.rectTransform.pivot.x * sizeX;
|
||||
var offsetY = -curveRenderer.rectTransform.pivot.y * sizeY;
|
||||
|
||||
Vector2[] points = new Vector2[curveRenderer.Points.Length];
|
||||
for (int i = 0; i < curveRenderer.Points.Length; i++)
|
||||
{
|
||||
points[i] = curveRenderer.Points[i];
|
||||
}
|
||||
|
||||
//Need to transform points to worldspace! when set to Relative
|
||||
if (curveRenderer.relativeSize)
|
||||
{
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
points[i] = new Vector2(points[i].x * sizeX + offsetX, points[i].y * sizeY + offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < points.Length - 1; i += 2)
|
||||
{
|
||||
|
@ -40,7 +57,14 @@ namespace UnityEngine.UI.Extensions
|
|||
if (check.changed)
|
||||
{
|
||||
Undo.RecordObject(curveRenderer, "Changed Curve Position");
|
||||
if (curveRenderer.relativeSize)
|
||||
{
|
||||
curveRenderer.Points[i] = new Vector2((p.x - offsetX) / sizeX, (p.y - offsetY) / sizeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
curveRenderer.Points[i] = p;
|
||||
}
|
||||
curveRenderer.transform.gameObject.SetActive(false);
|
||||
curveRenderer.transform.gameObject.SetActive(true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue