Merged in fix/UIConnectorAsPrefab (pull request #136)

UI Connector as Prefab fix
pull/413/head
Simon Jackson 2022-04-23 22:26:27 +00:00
commit a041f188b6
2 changed files with 9 additions and 1 deletions

View File

@ -15,6 +15,10 @@ namespace UnityEngine.UI.Extensions
parentCanvas = rt.GetComponentInParent<Canvas>(); parentCanvas = rt.GetComponentInParent<Canvas>();
if (parentCanvas == null) if (parentCanvas == null)
{ {
if (parent.parent == null)
{
return null;
}
parent = parent.parent.GetComponent<RectTransform>(); parent = parent.parent.GetComponent<RectTransform>();
SearchIndex++; SearchIndex++;
} }

View File

@ -18,7 +18,11 @@ namespace UnityEngine.UI.Extensions
private void Awake() private void Awake()
{ {
canvas = GetComponentInParent<RectTransform>().GetParentCanvas().GetComponent<RectTransform>(); var canvasParent = GetComponentInParent<RectTransform>().GetParentCanvas();
if (canvasParent != null)
{
canvas = canvasParent.GetComponent<RectTransform>();
}
rt = GetComponent<RectTransform>(); rt = GetComponent<RectTransform>();
lr = GetComponent<UILineRenderer>(); lr = GetComponent<UILineRenderer>();
} }