// ----- for Unity3D
// ■利用方法:
//
// … GameObjectに割り当てた、任意のコード上で
// private AssemblyCSharp.XMLLoder xLoader = null;
//
// … Awake などで
// xLoader = new AssemblyCSharp.XMLLoder();
// xLoader.asyncLoad(AssemblyCSharp.XMLLoder.XMLFilePath);
//
// … OnGUI などで
// if(xLoader.isLoaded)
// {
// GUI.TextField(new Rect(0, 0, 500, 100), xLoader.get1st());
// }
using System;
using System.IO;
using System.Xml;
using System.Threading;
namespace AssemblyCSharp
{
// XMLロードクラス。ただのローダなので MonoBehaviour 継承不要
public class XMLLoder
{
delegate void OnLoad();
private OnLoad onLoad = null;
public const String XMLFilePath = "http://t...content-available-to-author-only...r.com/statuses/public_timeline.xml";
private XmlDocument doc;
private XmlNodeList nodeListtext;
private bool bLoaded = false;
// 唯一のコンストラクタ
public XMLLoder()
{
// デリゲート用関数の準備
onLoad = this.done;
}
// 非同期ローダ
public void asyncLoad(String url)
{
// 一応 re-run 対策
if(doc == null)
{
// 子スレッド起こしてロード
Thread th = new Thread(new ThreadStart(delegate() {
// 本当はこれ、サブクラスメンバに持つ方が安全だが
doc = new XmlDocument();
doc.Load(url);
// 終了を委譲で通知
onLoad();
}));
th.Start();
}
}
// 終了が通知されるメソッド ※外部から叩かれても困るので private
private void done()
{
bLoaded = true;
nodeListtext = doc.SelectNodes("statuses/status/text");
}
// ロード完了してるか?
public bool isLoaded { get { return bLoaded; } }
// 適当な文字列の取得メソッド。適宜変更を
public String get1st()
{
if(!bLoaded) return null;
return nodeListtext[0].InnerText;
}
}
}
Ly8gLS0tLS0gZm9yIFVuaXR5M0QKCi8vIOKWoOWIqeeUqOaWueazle+8mgovLyAKLy8g4oCmIEdhbWVPYmplY3TjgavlibLjgorlvZPjgabjgZ/jgIHku7vmhI/jga7jgrPjg7zjg4nkuIrjgacKLy8gcHJpdmF0ZSBBc3NlbWJseUNTaGFycC5YTUxMb2RlciB4TG9hZGVyID0gbnVsbDsKLy8gCi8vIOKApiBBd2FrZSDjgarjganjgacK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