Two yield or not two yield (pattern?)

Sorry for the lame subject, but I am having troubles with yield while loading some bytes from a WWW object in C#.


Load multiple files with WWW from a webserver, from a UnityPlayer webclient.

But I need to wait for EVERY file, until the game can start.

Some of the files are leveldata telling how to build the level others are players and NPC data etc.

And everything is needed before the simulation/game may start.


Should I spawn multiple WWW objects and yield them all or only one at the time?
The server I am loading from could be different addresses (CDN’s) so speed is not the problem. My problem is only what pattern is recommended and why and … ouch! HOW?!

I have a yield running now, loading 1000 bytes from a webserver, it returns the 1000 bytes (sooner or later) but everything starts, so I will need to make some kinda state-machine globally too I guess.

I think I will yield until someone can answer this.

You can spawn them all at one time, but you probably won’t save much time since Unity isn’t multithreaded. Only one will ever be loading at any given time so your speed probably won’t be noticeably different. It shouldn’t change if one loads fully then you load the next one or if you load a little bit of each during each frame. Personally I would put it in a loop and load each one after the next just because it looks nice:

for(var i = 0; i < URLS.Length; i++) {
      URLS _= new WWW(addresses*);*_

yield return URLS*;*
//do something else with the data;
If you know .Net sockets you might be able to do something similar and then push that onto different threads.