Monday, January 31, 2011

UnityWeb - Why does it exist?

The latest version of UnityWeb now works with iOS, Mac, PC, and WebPlayer builds of Unity3D games.

If you haven't done a lot of work with HTTP, you are probably wondering, "Why is UnityWeb needed?".

Here is a contrived, yet realistic scenario which demonstrates something you can do with UnityWeb, but is impossible with the WWW class.

Posit: Your game needs to download an avatar image for each player and use it as a texture. A player can update their avatar image, so you must periodically check to see if the image has changed.

Using the Unity3D WWW class, you might do something like this:
for each member
download avatar image
update avatar texture

If you have 50 avatars in one game, you will download 50 different images. Every 10 minutes or so, you re-download the images.

Using UnityWeb, you can do something better.
for each member
download avatar image
if image has changed, update avatar texture
UnityWeb will only redownload a URL if it has changed since you last downloaded it. UnityWeb uses the magic of Etags to make this work. To make this type of caching happen, you simply add:
request.useCache = true;
This results in faster response times, less web traffic, and you could poll much quicker than every 10 minutes, as only changes will be downloaded.

1 comment:

das said...

Wow ! Super impressed.
Thanks for the MIT license.

Popular Posts