From 2294f349055004fb9e8bdf1dde5f0bc53c1a308a Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Fri, 4 Aug 2017 20:36:25 +0100 Subject: [PATCH] Performance update to UILineConnector only draw when child transforms move. https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/123/uilinerenderer-issues-with-specifying --- Scripts/Utilities/UILineConnector.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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