I’m trying to essentially generate a list of thumbnails in game based on files from a folder on the user’s computer. This works fine (code below), but completely stalls the application until it’s finished loading.
Is there a way to do this in the background so I can show a loading animation or something? It’s for VR, so it’s extra important not to have it freeze for a second.
The more image files in the folder path, the longer it freezes, understandably.
I’ve tried using a coroutine, but that still causes the freeze.
Any ideas? Thanks!!
Here’s the code:
bool framesFinishedLoading = false;
private void OnEnable()
{
StartCoroutine(loadFrames());
}
IEnumerator loadFrames()
{
framesFinishedLoading = false;
while (!framesFinishedLoading)
{
selectableFramePaths = Directory.GetFiles(saveLoadManager.imageOutputPath, "*.png");
Array.Reverse(selectableFramePaths);
generateSelectableFrames();
framesFinishedLoading = true;
}
yield break; // I've tried return null also and still the same thing.
}
void generateSelectableFrames()
{
for (int i = 0; i < selectableFramePaths.Length; i++)
{
//yield return new WaitForEndOfFrame();
RawImage selectableFrame = Instantiate(selectableFramePrefab, selectableFrameParent.transform);
selectableFrame.texture = HelperMethods.LoadPNG(selectableFramePaths*);*
selectableFrame.gameObject.SetActive(true);
selectableFrames.Add(selectableFrame);
}
framesFinishedLoading = false;
}