Fixed editor handles for Relative size #Phew

release
Simon Jackson 2017-06-21 23:44:10 +01:00
parent c4c6c81e80
commit 11309d2d82
1 changed files with 26 additions and 2 deletions

View File

@ -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);
}