When launching the game, I’m loading a lot of data from a database. To lighten the pain I want to show a load bar to show the progress, along with a text informing the user what’s being loaded. (in a funny format of course)
For example I have this code:
public void Start()
{
if(LoadingState == LoadingState.StartFromDesktop)
{
SetText("Get Countries", 10);
WorldModel.Countries = DataGameObjects.GetCountries();
SetText("Get Continents", 25);
WorldModel.SubContinents = DataGameObjects.GetSubContinents();
WorldModel.Continents = DataGameObjects.GetContinents();
WorldModel.Areas = DataGameObjects.GetAreas();
WorldModel.States = DataGameObjects.GetStates();
}
}
private void SetText(string text, int progress)
{
_task.text = text;
_percentage.text = progress + " %";
_progressbar.value = (float)progress / 100;
}
Obviously, this doesn’t do what I want. It just changes the text to ‘Get Continents’ at the end of the method, while freezing the loading screen because its busy.
I tried using Coroutines, but that threw an error because it wanted me to return a string of a method.
Neither could I work it out using async tasks.
Any suggestions?
Also, what would be the best way to calculate the progress of loading an .sqlite file and .xml files?