Skip to content

Commit fc64d38

Browse files
authored
feat: allow preloading selectionElements (#243)
2 parents 981de19 + 1967c05 commit fc64d38

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Runtime/AvatarCreator/Scripts/UI/Elements/SelectionElement.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,22 @@ public abstract class SelectionElement : MonoBehaviour
1919
[SerializeField] private SelectionButton buttonElementPrefab;
2020
[SerializeField] private GameObject selectedIconPrefab;
2121
[SerializeField] private Transform buttonContainer;
22-
private GameObject selectedIcon;
22+
23+
private GameObject _selectedIcon;
24+
private GameObject selectedIcon
25+
{
26+
get
27+
{
28+
if (_selectedIcon)
29+
{
30+
return _selectedIcon;
31+
}
32+
_selectedIcon = Instantiate(selectedIconPrefab, buttonContainer);
33+
selectedIcon.SetActive(false);
34+
return _selectedIcon;
35+
}
36+
}
37+
2338

2439
[Space(5)]
2540
[Header("Events")]
@@ -28,12 +43,6 @@ public abstract class SelectionElement : MonoBehaviour
2843

2944
protected Transform ButtonContainer => buttonContainer;
3045

31-
private void Start()
32-
{
33-
selectedIcon = Instantiate(selectedIconPrefab, buttonContainer);
34-
selectedIcon.SetActive(false);
35-
}
36-
3746
/// <summary>
3847
/// Creates button elements for each asset in the provided array.
3948
/// This function is generic and can work with any asset type that implements the IAssetData interface.

0 commit comments

Comments
 (0)