Skip to content

Commit 7da6948

Browse files
Update UIVertical Scroller to be more efficient for U6 and update example
1 parent e665951 commit 7da6948

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

Runtime/Scripts/Layout/UIVerticalScroller.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public class UIVerticalScroller : MonoBehaviour
6868
public int FocusedElementIndex { get; private set; }
6969

7070
public RectTransform Center { get => center; set => center = value; }
71+
public RectTransform ElementSize { get => elementSize; set => elementSize = value; }
72+
public ScrollRect ScrollRectComponent { get => scrollRect; set => scrollRect = value; }
73+
public GameObject[] ArrayOfElements { get => arrayOfElements; set => arrayOfElements = value; }
7174

7275
public string Result { get; private set; }
7376

@@ -94,29 +97,6 @@ public void Awake()
9497
{
9598
scrollRect = GetComponent<ScrollRect>();
9699
}
97-
98-
if (!center)
99-
{
100-
Debug.LogError("Please define the RectTransform for the Center viewport of the scrollable area");
101-
}
102-
103-
if (!elementSize)
104-
{
105-
elementSize = center;
106-
}
107-
108-
if (arrayOfElements == null || arrayOfElements.Length == 0)
109-
{
110-
var childCount = ScrollingPanel.childCount;
111-
if (childCount > 0)
112-
{
113-
arrayOfElements = new GameObject[childCount];
114-
for (int i = 0; i < childCount; i++)
115-
{
116-
arrayOfElements[i] = ScrollingPanel.GetChild(i).gameObject;
117-
}
118-
}
119-
}
120100
}
121101

122102
/// <summary>
@@ -172,6 +152,30 @@ private void AddListener(GameObject button, int index)
172152

173153
public void Start()
174154
{
155+
if (!center)
156+
{
157+
Debug.LogError("Please define the RectTransform for the Center viewport of the scrollable area");
158+
return;
159+
}
160+
161+
if (!elementSize)
162+
{
163+
elementSize = center;
164+
}
165+
166+
if (arrayOfElements == null || arrayOfElements.Length == 0)
167+
{
168+
var childCount = ScrollingPanel.childCount;
169+
if (childCount > 0)
170+
{
171+
arrayOfElements = new GameObject[childCount];
172+
for (int i = 0; i < childCount; i++)
173+
{
174+
arrayOfElements[i] = ScrollingPanel.GetChild(i).gameObject;
175+
}
176+
}
177+
}
178+
175179
if (scrollUpButton)
176180
{
177181
scrollUpButton.GetComponent<Button>().onClick.AddListener(() => ScrollUp());

0 commit comments

Comments
 (0)