Es2 Save/Load Callback?

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
robot55
Posts: 1
Joined: Fri Jul 27, 2018 7:11 pm

Es2 Save/Load Callback?

Post by robot55 »

Hi,

I'm developing a slideshow app of sorts.
Users add a photo and an audio clip for each slide and then entire slideshow is saved to disk.
I am using ES.Save and ES2.Load and everything is working. (using ES2.Load<AudioClip> and ES2.Load<Texture2d> respectively where needed)

The problem is loading an entire slideshow take a bit of time (15-20 seconds on slower devices) and I would like to put on some loading screen animation while that is happening - but I can't seem to find a way to "check" when the actual loading is finished.
Is there a way to get a callback?

Any suggestions on what to do?

here are my methods using ES2:

public Texture2D loadPageImage(string currentBookFileName, int pageIndex){
Debug.Log("<< Load Texture Method Began >>");
string bookFolderPath = currentBookFileName;
string pageFolderPath = Path.Combine (bookFolderPath, "Page_" + pageIndex.ToString ("000"));
string photoFileName = "pagePhoto.R55";
string pathToFile = Path.Combine (pageFolderPath, photoFileName);
Debug.Log ("pathToFile: " + pathToFile);
if (ES2.Exists (pathToFile)) {
Debug.Log ("## Load Texture Method completed ##");
return ES2.Load<Texture2D> (pathToFile);
} else {
Debug.Log ("Texture path doesn't exist: " + pathToFile);
return null;
}
}

public AudioClip loadPageAudio(string currentBookFileName, int pageIndex){
Debug.Log("<< Load Audio Method Began >>");
string bookFolderPath = currentBookFileName;
string pageFolderPath = Path.Combine (bookFolderPath, "Page_" + pageIndex.ToString ("000"));
string audioFileName = "pageAudio.R55";
string pathToFile = Path.Combine (pageFolderPath, audioFileName);
Debug.Log ("pathToFile: " + pathToFile);
if (ES2.Exists (pathToFile)) {
Debug.Log ("## Load Audio Method completed ##");
return ES2.Load<AudioClip> (pathToFile);
} else {
Debug.Log ("Audio-File path doesn't exist: " + pathToFile);
return null;
}
}


And here's the main loop using these methods:

DirectoryInfo dir = new DirectoryInfo(Path.Combine(Application.persistentDataPath, currentBookFileName));
DirectoryInfo[] pagesInBook = dir.GetDirectories("Page_*");
lastPageToLoad = pagesInBook.Length-1;
Debug.Log ("setting lastPageToLoad to: " + lastPageToLoad);
screenBook.pages.Clear();
int stash = pageIndex;
pageIndex = 0;
foreach (DirectoryInfo pageFolder in pagesInBook) {
SinglePage newPage = new SinglePage ();
newPage.texture = savemanager.loadPageImage (currentBookFileName, pageIndex);
newPage.clip = savemanager.loadPageAudio (currentBookFileName, pageIndex);
screenBook.pages.Add (newPage);
pageIndex++;
}
pageIndex = stash;


I'd appreciate any help I can get, thanks in advance,
David
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Es2 Save/Load Callback?

Post by Joel »

Hi there,

Easy Save runs synchronously, so it is completed when the method returns.

If you wish to run Easy Save asynchronously you should run it in a separate thread.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked