fork download
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6. public class NetworkService : MonoBehaviour
  7. {
  8. private const string xmlApi = "http://a...content-available-to-author-only...p.org/data/2.5/weather?q=Chicago,us&mode=xml";
  9. private const string webImage = "http://u...content-available-to-author-only...a.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg";
  10.  
  11. private bool IsResponseValid(WWW www)
  12. {
  13. if(!string.IsNullOrEmpty(www.error))
  14. {
  15. Debug.Log("bad connection");
  16.  
  17. return false;
  18. }
  19.  
  20. else if(string.IsNullOrEmpty(www.text))
  21. {
  22. Debug.Log("bad data");
  23.  
  24. return false;
  25. }
  26.  
  27. else
  28. {
  29. //all good
  30. return true;
  31. }
  32. }
  33.  
  34. private IEnumerator CallAPI (string url, Action<string> callback)
  35. {
  36. WWW www = new WWW(url);
  37.  
  38. yield return www;
  39.  
  40. if(!IsResponseValid(www))
  41. {
  42. yield break;
  43. }
  44.  
  45. callback(www.text);
  46. }
  47.  
  48. public IEnumerator GetWeatherXML(Action<string> callback)
  49. {
  50. return CallAPI(xmlApi, callback);
  51. }
  52.  
  53. public IEnumerator DownloadImage(Action<Texture2D> callback)
  54. {
  55. WWW www = new WWW(webImage);
  56.  
  57. yield return www;
  58.  
  59. callback(www.texture);
  60. }
  61.  
  62. // Use this for initialization
  63. void Start ()
  64. {
  65.  
  66. }
  67.  
  68. // Update is called once per frame
  69. void Update ()
  70. {
  71.  
  72. }
  73. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(3,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing an assembly reference?
prog.cs(6,31): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing an assembly reference?
prog.cs(11,34): error CS0246: The type or namespace name `WWW' could not be found. Are you missing an assembly reference?
prog.cs(53,45): error CS0246: The type or namespace name `Texture2D' could not be found. Are you missing an assembly reference?
Compilation failed: 4 error(s), 0 warnings
stdout
Standard output is empty