From 11309d2d821393b423302a481b8deb724ab10c45 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Wed, 21 Jun 2017 23:44:10 +0100 Subject: [PATCH] Fixed editor handles for Relative size #Phew --- Editor/BezierLineRendererEditor.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Editor/BezierLineRendererEditor.cs b/Editor/BezierLineRendererEditor.cs index 34b73ac..1a25109 100644 --- a/Editor/BezierLineRendererEditor.cs +++ b/Editor/BezierLineRendererEditor.cs @@ -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"); - curveRenderer.Points[i] = p; + 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); }