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