diff --git a/Scripts/Utilities/UILineConnector.cs b/Scripts/Utilities/UILineConnector.cs index edc4c22..989be4e 100644 --- a/Scripts/Utilities/UILineConnector.cs +++ b/Scripts/Utilities/UILineConnector.cs @@ -11,6 +11,7 @@ namespace UnityEngine.UI.Extensions // The elements between which line segments should be drawn public RectTransform[] transforms; + private Vector2[] previousPositions; private RectTransform canvas; private RectTransform rt; private UILineRenderer lr; @@ -29,6 +30,19 @@ namespace UnityEngine.UI.Extensions { return; } + //Performance check to only redraw when the child transforms move + if (previousPositions != null && previousPositions.Length == transforms.Length) + { + bool updateLine = false; + for (int i = 0; i < transforms.Length; i++) + { + if (!updateLine && previousPositions[i] != transforms[i].anchoredPosition) + { + updateLine = true; + } + } + if (!updateLine) return; + } // Get the pivot points Vector2 thisPivot = rt.pivot; @@ -61,6 +75,12 @@ namespace UnityEngine.UI.Extensions lr.Points = points; lr.RelativeSize = false; lr.drivenExternally = true; + + previousPositions = new Vector2[transforms.Length]; + for (int i = 0; i < transforms.Length; i++) + { + previousPositions[i] = transforms[i].anchoredPosition; + } } } } \ No newline at end of file