Created
April 19, 2012 14:23
-
-
Save jdolan/2421271 to your computer and use it in GitHub Desktop.
Unity3D deferred WWW loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Example : MonoBehaviour { | |
// Some other state / variables here | |
// Load the specified JSON resource as the DataSet | |
IEnumerator Load(string url) { | |
WWW json = new WWW(url); | |
yield return json; | |
if (json.error == null) { | |
elements = (IList<IDictionary<string, object>>) JsonFx.Json.JsonReader.Deserialize(json.text); | |
OnLoad(); // WORKS -- this gets called, \o/ | |
} else { | |
Debug.LogError("Failed to download " + url + ": " + json.error); | |
} | |
} | |
IEnumerator LoadMultiple(IEnumerable<string> urls) { | |
foreach (string url in urls) { | |
WWW json = new WWW(url); | |
yield return json; | |
if (json.error == null) { | |
// append all to the internal list | |
} else { | |
Debug.LogError("Failed to download " + serviceUrl + symbol); | |
} | |
} | |
OnLoad(); // THIS IS NOT CALLED, WHY? | |
} | |
IEnumerator Start() { | |
return Load("http://example.com/resource.json"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment