From 796f66c31058308e01c700fcd83e6673666f7571 Mon Sep 17 00:00:00 2001 From: SimonDarksideJ Date: Sat, 17 Jun 2023 18:33:22 +0100 Subject: [PATCH] Updated LineRenderer and UILIneConnector implementations to both be safer and include warning about placing a UILineRenderer at any other position than 0,0,0. --- Runtime/Scripts/Primitives/UILineRenderer.cs | 6 ++++-- Runtime/Scripts/Utilities/UILineConnector.cs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/Primitives/UILineRenderer.cs b/Runtime/Scripts/Primitives/UILineRenderer.cs index 7225145..019c3b6 100644 --- a/Runtime/Scripts/Primitives/UILineRenderer.cs +++ b/Runtime/Scripts/Primitives/UILineRenderer.cs @@ -296,8 +296,6 @@ namespace UnityEngine.UI.Extensions PopulateMesh (vh, pointsToDraw); } } - - } private UIVertex[] CreateLineCap(Vector2 start, Vector2 end, SegmentType type) @@ -501,6 +499,10 @@ namespace UnityEngine.UI.Extensions { m_points = new Vector2[1]; } + if (transform.GetComponent().position != Vector3.zero) + { + Debug.LogWarning("A Line Renderer component should be on a RectTransform positioned at (0,0,0), do not use in child Objects.\nFor best results, create separate RectTransforms as children of the canvas positioned at (0,0) for a UILineRenderer and do not move."); + } } } } diff --git a/Runtime/Scripts/Utilities/UILineConnector.cs b/Runtime/Scripts/Utilities/UILineConnector.cs index 487dec5..77a3fc9 100644 --- a/Runtime/Scripts/Utilities/UILineConnector.cs +++ b/Runtime/Scripts/Utilities/UILineConnector.cs @@ -40,6 +40,10 @@ namespace UnityEngine.UI.Extensions bool updateLine = false; for (int i = 0; i < transforms.Length; i++) { + if (transforms[i] == null) + { + continue; + } if (!updateLine && previousPositions[i] != transforms[i].position) { updateLine = true; @@ -60,6 +64,10 @@ namespace UnityEngine.UI.Extensions // First, convert the pivot to worldspace for (int i = 0; i < transforms.Length; i++) { + if (transforms[i] == null) + { + continue; + } worldSpaces[i] = transforms[i].TransformPoint(thisPivot); } @@ -83,6 +91,10 @@ namespace UnityEngine.UI.Extensions previousPositions = new Vector3[transforms.Length]; for (int i = 0; i < transforms.Length; i++) { + if (transforms[i] == null) + { + continue; + } previousPositions[i] = transforms[i].position; } }