fork download
  1. // ----- for Unity3D
  2.  
  3. // ■利用方法:
  4. //
  5. // … GameObjectに割り当てた、任意のコード上で
  6. // private AssemblyCSharp.XMLLoder xLoader = null;
  7. //
  8. // … Awake などで
  9. // xLoader = new AssemblyCSharp.XMLLoder();
  10. // xLoader.asyncLoad(AssemblyCSharp.XMLLoder.XMLFilePath);
  11. //
  12. // … OnGUI などで
  13. // if(xLoader.isLoaded)
  14. // {
  15. // GUI.TextField(new Rect(0, 0, 500, 100), xLoader.get1st());
  16. // }
  17.  
  18. using System;
  19. using System.IO;
  20. using System.Xml;
  21. using System.Threading;
  22.  
  23. namespace AssemblyCSharp
  24. {
  25. // XMLロードクラス。ただのローダなので MonoBehaviour 継承不要
  26. public class XMLLoder
  27. {
  28. delegate void OnLoad();
  29. private OnLoad onLoad = null;
  30.  
  31. public const String XMLFilePath = "http://t...content-available-to-author-only...r.com/statuses/public_timeline.xml";
  32.  
  33. private XmlDocument doc;
  34. private XmlNodeList nodeListtext;
  35. private bool bLoaded = false;
  36.  
  37. // 唯一のコンストラクタ
  38. public XMLLoder()
  39. {
  40. // デリゲート用関数の準備
  41. onLoad = this.done;
  42. }
  43.  
  44. // 非同期ローダ
  45. public void asyncLoad(String url)
  46. {
  47. // 一応 re-run 対策
  48. if(doc == null)
  49. {
  50. // 子スレッド起こしてロード
  51. Thread th = new Thread(new ThreadStart(delegate() {
  52.  
  53. // 本当はこれ、サブクラスメンバに持つ方が安全だが
  54. doc = new XmlDocument();
  55. doc.Load(url);
  56.  
  57. // 終了を委譲で通知
  58. onLoad();
  59. }));
  60. th.Start();
  61. }
  62. }
  63.  
  64. // 終了が通知されるメソッド ※外部から叩かれても困るので private
  65. private void done()
  66. {
  67. bLoaded = true;
  68. nodeListtext = doc.SelectNodes("statuses/status/text");
  69. }
  70.  
  71. // ロード完了してるか?
  72. public bool isLoaded { get { return bLoaded; } }
  73.  
  74. // 適当な文字列の取得メソッド。適宜変更を
  75. public String get1st()
  76. {
  77. if(!bLoaded) return null;
  78. return nodeListtext[0].InnerText;
  79. }
  80. }
  81.  
  82. }
  83.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty