// Use this for initialization void Start() { Debug.Log("[Example][Start]"); AsyncTask asyncTask = gameObject.AddComponent <AsyncTask>(); asyncTask.SetUrl("https://sunnywalk.herokuapp.com/api/game_result/new") .AddQueryParams("token", "hxlebnbyciaxzukfj") .AddQueryParams("secret", "8hNwxVMbAUptlmfC4xNMbZuvVW5XVnPXXY2MWJk14T4=") .AddQueryParams("student_id", 5 + "") .AddQueryParams("duration", 456 + "") .AddQueryParams("object_total", 20 + "") .AddQueryParams("object_caught", 12 + "") .Before((t) => { AsyncTask task = (AsyncTask)t; Debug.Log("[TRACE][ASYNCTASK] " + task.GetUrl() + task.GetQueryParams()); }) .Progress((p) => { float progress; float.TryParse(p.ToString(), out progress); Debug.Log("[TRACE][ASYNCTASK] Progress: " + (progress * 100) + "%"); }) .After((data) => { WWW download = (WWW)data; Debug.Log("[INFO][ASYNCTASK] Downloaded: " + download.text); }).Start(); }
// Use this for initialization void Start() { //Get list of students AsyncTask asyncTask = gameObject.AddComponent <AsyncTask>(); asyncTask.SetUrl("https://sunnywalk.herokuapp.com/api/student/all.json") .AddQueryParams("token", "dzfdmpkumxqqgnadd") .AddQueryParams("secret", "Uor593YqX58xiZGJRAJOlGAtvH6pVIUGkiBxAQfooe0=") .Before((t) => { AsyncTask task = (AsyncTask)t; Debug.Log("[TRACE][ASYNCTASK] " + task.GetUrl() + task.GetQueryParams()); }) .Progress((p) => { float progress; float.TryParse(p.ToString(), out progress); Debug.Log("[TRACE][ASYNCTASK] Progress: " + (progress * 100) + "%"); }) .After((data) => { WWW download = (WWW)data; //Debug.Log("[INFO][ASYNCTASK] Downloaded: " + download.text); if (string.IsNullOrEmpty(download.error)) { //success, response text Debug.Log(download.text); var jObj = JSON.Parse(download.text); for (int i = 0; i < jObj.Count; i++) { InsertOption(jObj[i]["name"].Value); Student s = gameObject.AddComponent <Student>(); s.SetId(jObj[i]["id"].AsInt); s.SetName(jObj[i]["name"].Value); s.SetGender(jObj[i]["gender"].Value); studentList.Add(s); } } else { Debug.Log("Error downloading: " + download.error); } }).Start(); }