WWW wrapper for Unity3D

WWW wrapper for Unity - Documentation

How to install

Add [WWW wrapper for Unity] package to your Unity project.

If you do not need tests, just add [UCSS.dll] to [Plugins] folder in your project.

How to configure

Use [UCSSconfig] to setup several parameters.

UCSSconfig.requestDefaultTimeOut – maximal time of expectation of response from server (in seconds).

UCSSconfig.requestDefaultTimeOutCheck – delta time of requestDefaultTimeOut checking (in seconds, float).

How to use

WWW wrapper for Unity is a part of UCSS (Client-Server Solution for Unity). For this reason using of this wrapper is closely linked to UCSS.

Use [Using Ucss;] in files, where you’ll be using UCSS (and it's WWW wrapper).

Use [UCSS.HTTP] to call wrapper's methods.

Sending Requests

There are two ways to send a request:

1. By passing request parameters directly to necessary method.

2. Using object [HTTPRequest]

In most cases you can use first way, but in some situations (for more sophisticated setup of request) you may need second way with using object [HTTPRequest].

UCSS.HTTP.GetString (analogue of WWW.text)

Makes GET request to server and expects text information in response.

Parameters:

  • string url – address where request will be passed

  • EventHandlerHTTPString stringCallback — method, which will be called when response is received

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.GetString(HTTPRequest request)

UCSS.HTTP.GetBytes (analogue of WWW.bytes)

Makes GET request to server and expects bytes in response.

Parameters:

  • string url – address where request will be passed

  • EventHandlerHTTPBytes bytesCallback — method, which will be called when response is received

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.GetBytes(HTTPRequest request)

UCSS.HTTP.GetTexture (analogue of WWW.texture)

Makes GET request to server and expects an image in JPG or PNG format in response.

Parameters:

  • string url – address where request will be passed

  • EventHandlerHTTPTexture textureCallback — method, which will be called when response is received

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.GetTexture(HTTPRequest request)

UCSS.HTTP.GetAssetBundle (analogue of WWW.assetBundle)

Makes GET request to server and expects an AssetBundle data in response.

Parameters:

  • string url – address where request will be passed

  • EventHandlerAssetBundle assetBundleCallback — method, which will be called when response is received

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.GetAssetBundle(HTTPRequest request)

UCSS.HTTP.GetAssetBundleOrCache (analogue of WWW.LoadFromCacheOrDownload)

Loads an AssetBundle with the specified version number from the cache. If the AssetBundle is not currently cached, it will automatically be downloaded and stored in the cache for future retrieval from local storage.

In this method [HTTPRequest] object is used.

Parameters:

  • string url - address where request will be passed
  • EventHandlerAssetBundle assetBundleCallback - method, which will be called when response is received
  • int assetVersion - version of the AssetBundle.
  • uint assetCRC - an optional CRC-32 Checksum of the uncompressed contents.
  • EventHandlerServiceError onError - method, which will be called when error appears
  • EventHandlerServiceTimeOut onTimeOut - method, which will be called due to timeout
  • int timeOut - maximum time (in seconds) of getting response from server.

Example:

HTTPRequest request = new HTTPRequest(); request.url = "http://ucss.webjema.com/tests/http/assets/SpheresInAssetBundle.unity3d"; request.onError = new EventHandlerServiceError(this.OnHTTPError); request.onTimeOut = new EventHandlerServiceTimeOut(this.OnHTTPTimeOut); request.timeOut = 5; request.assetBundleCallback = new EventHandlerAssetBundle(this.OnAssetDownloaded); request.assetVersion = 1; request.assetCRC = 0; UCSS.HTTP.GetAssetBundleOrCache(request)

UCSS.HTTP.GetAudioClip (analogue of WWW.audioClip)

Makes GET request to server and expects an audio clip in Ogg(Web/Standalones), MP3(phones,Flash), WAV, XM, IT, MOD or S3M format in response.

Parameters:

  • string url – address where request will be passed

  • EventHandlerAudioClip audioClipCallback — method, which will be called when response is received

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.GetAudioClip(HTTPRequest request)

UCSS.HTTP.GetMovie (analogue of WWW.movie)

Makes GET request to server and expects a movie in Ogg Theora format in response.

Parameters:

  • string url – address where request will be passed

  • EventHandlerMovieTexture movieCallback — method, which will be called when response is received

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.GetMovie(HTTPRequest request)

UCSS.HTTP.PostBytes

Makes POST request to server with raw post data (byte array).

Parameters:

  • string url – address where request will be passed

  • byte[] bytes - a byte array of data to be posted to the url.
  • Hashtable headers - a hash table of custom headers to send with the request
  • EventHandlerHTTPBytes bytesCallback — method, which will be called when response is received. Also [EventHandlerHTTPString] callback is allowed.

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.PostBytes(HTTPRequest request)

UCSS.HTTP.PostForm

Makes POST request to server with form data contained in a WWWForm parameter.

Parameters:

  • string url – address where request will be passed

  • WWWForm formData - a WWWForm instance containing the form data to post.
  • EventHandlerHTTPBytes bytesCallback — method, which will be called when response is received. Also [EventHandlerHTTPString] callback is allowed.

  • EventHandlerServiceError onError (optional) — method, which will be called when error appears

  • EventHandlerServiceTimeOut onTimeOut (optional) — method, which will be called due to timeout

  • int timeOut (optional) — maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called

The same method can be called with parameter [HTTPRequest]:

UCSS.HTTP.PostForm(HTTPRequest request)

HTTPRequest

As parameter in [UCSS.HTTP] methods you can use object of [HTTPRequest] class

  • string url - address for request
  • string transactionId - unique identifier of request (passes to callback with response, as well as to other callbacks). It will be generated automatically if it isn't specified.
  • EventHandlerServiceError onError - will be called in case of errors.
  • EventHandlerServiceTimeOut onTimeOut - will be called if time of transferring the request will exceed [timeOut]
  • int timeOut - maximum time (in seconds) of getting response from server. If response will not be received during this time, method [onTimeOut] will be called
  • byte[] bytes — is used in POST requests
  • WWWForm formData — is used in POST requests
  • Hashtable headers — is used in POST requests during sending byte array
  • int assetVersion — is used in GetAssetBundleOrCache
  • uint assetCRC — is used in GetAssetBundleOrCache
  • ThreadPriority threadPriority — is used in GetAssetBundle
  • EventHandlerHTTPWWW wwwCallback — if specified, it will be called in case of successful query finish. WWW object will be transferred as a parameter.
  • EventHandlerHTTPTexture textureCallback — is used for receiving Texture2D
  • EventHandlerHTTPTexture textureNonReadableCallback — is used for receiving a non-readable Texture2D generated from the downloaded data (WWW.textureNonReadable)
  • EventHandlerHTTPBytes bytesCallback — is used for receiving byte[]
  • EventHandlerHTTPString stringCallback — is used for receiving string
  • EventHandlerAssetBundle assetBundleCallback — is used for receiving AssetBundle
  • EventHandlerAudioClip audioClipCallback — is used for receiving AudioClip
  • EventHandlerMovieTexture movieTextureCallback — is used for receiving MovieTexture
  • EventHandlerDownloadProgress downloadProgress — if specified, it will be called each time, when [WWW.progress] changes its value
  • EventHandlerUploadProgress uploadProgress — if specified, it will be called each time, when [WWW.uploadProgress] changes value

Delegates (callbacks)

  • EventHandlerServiceError(string error, string transactionId);
  • EventHandlerServiceTimeOut(string transactionId);
  • EventHandlerHTTPWWW(WWW www, string transactionId);
  • EventHandlerAssetBundle(AssetBundle assetBundle, string transactionId);
  • EventHandlerHTTPBytes(byte[] bytes, string transactionId);
  • EventHandlerHTTPTexture(Texture2D texture, string transactionId);
  • EventHandlerHTTPString(string text, string transactionId);
  • EventHandlerAudioClip(AudioClip audioClip, string transactionId);
  • EventHandlerMovieTexture(MovieTexture movieTexture, string transactionId);
  • EventHandlerDownloadProgress(float progress);
  • EventHandlerUploadProgress(float progress);
  • EventHandlerServiceError(string error, string transactionId);
  • EventHandlerServiceTimeOut(string transactionId);

Server side

You can use this simple php scripts and several files for tests (archive 3,6Mb).