I am using the Parse SDK for Unity to retrieve some files and save to the resource directory. When I call parse.findAsync (), it creates another task, and it is impossible for me to call WWW to load the URL obtained from the analysis. I need:
- Parse Challenge
- Get information about the parade
- Call www for every file i got from the session
- Wait for it to be completed;
- Return result;
I tried this:
public IEnumerator GetXXXAsync(String objectId){
var query = ParseObject.GetQuery("xxx").WhereEqualTo("yyy", ParseObject.
CreateWithoutData("zzz", objectId));
List<String> urlList = new List<String>();
Album album = null;
query.FindAsync().ContinueWith(t =>
{
var tasks = new List<Task>();
Task task = Task.FromResult(0);
foreach (var result in t.Result)
{
ParseObject obj = result;
ParseFile file = (ParseFile)obj.Get<ParseFile>("image");
if(file != null){
urlList.Add(file.Url.ToString());
tasks.Add(GetImageAsync(file.Url.ToString(), "image.png"));
}
}
return Task.WhenAll(tasks);
}).Unwrap().ContinueWith(_ =>
{
gameManager.SendOk();
});
return null;
}
private WWW WaitForImage(String url, string filename) {
WWW www = new WWW( url );
while(!www.isDone){
Debug.Log("Waiting");
}
Utils.SaveFileFromTexture(www.texture, (gameManager.GetResourcesPath() + "/Textures/" + filename));
Debug.Log("Saving file ");
return www;
}
public Task<WWW> GetImageAsync(String url, string filename) {
var task = new TaskCompletionSource<WWW>();
Debug.Log("GetImageAsync " + filename);
task.SetResult(WaitForImage(url, filename));
return task.Task;
}
I tried to get IEnumerator instead of WWW, but I always get that WWW "cannot be called outside the main thread". Is there anything I can do to call WWW outside the main thread? Or something else?
Tks
source
share