Disclaimer: This is a friggin’ really complicated question. Probably what I wasted the most time out of anything I’ve ever done with Unity 3D in the past 5 years or so. And I’m still stuck here… So, be aware about all links before trying to answer! (although this will be most likely unanswered for evah!)
I need 2 things:
- check for internet connectivity.
- compare file bundle versions to see if differs from local and web.
WebRequest could solve both. I could get headers on any URL, thus verifying not only internet connectivity, but also if the server is up, without relying on unreliable ping. Also I could get the file length, without needing to download it all first with
WWW, and that would be good enough to check if the file is different.
First problem is that method
GetResponse isn’t asynchronous like
WWW and so it locks up the whole application while it is checking. When doing for several, hundreds, of files, it sums up a lot. Second problem is that
BeginGetResponse is so complicated to implement that I found it impossible until now.
I’ve built many versions of a fine script, I called it
WebAsync, but now I just can’t get around the issues on why
WebResponse is failing. I do know it can be way more complex than I would expect, but even then, it still gives me random results when I test, still bringing
null when it shouldn’t.
Just today I decided to drop
WebAsync in favor of
WWW, and it was working much better already… But then I stumbled upon the already mentioned problem with getting file length and now I think it won’t work because of need #2. Unless I drop the idea of using the file length and use a separated bundle version control file, kinda like unity do with external version control, and create a “meta” for each bundle.
So, there are actually 2 kind of right answers (as usual) here. For the title, or for these needs (if there is another option). But, please, don’t tell me I’ll have to go forward with the last idea and keep meta files everywhere! I hate that idea…