using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class NetworkService : MonoBehaviour { private const string xmlApi = "http://a...content-available-to-author-only...p.org/data/2.5/weather?q=Chicago,us&mode=xml"; private const string webImage = "http://u...content-available-to-author-only...a.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg"; private bool IsResponseValid(WWW www) { if(!string.IsNullOrEmpty(www.error)) { Debug.Log("bad connection"); return false; } else if(string.IsNullOrEmpty(www.text)) { Debug.Log("bad data"); return false; } else { //all good return true; } } private IEnumerator CallAPI (string url, Action callback) { WWW www = new WWW(url); yield return www; if(!IsResponseValid(www)) { yield break; } callback(www.text); } public IEnumerator GetWeatherXML(Action callback) { return CallAPI(xmlApi, callback); } public IEnumerator DownloadImage(Action callback) { WWW www = new WWW(webImage); yield return www; callback(www.texture); } // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }