利用WWW类获取Text并且在unityUGUI的Text中显示

先创建一个txt的文本,另存为修改一下格式改成UEF—8的。然后放入服务器或者本地都行。然后进行读取。

上代码

using UnityEngine.UI;
using System.IO;
public class GetBundle : MonoBehaviour {
public Text mytext;
void Start () 
{
StartCoroutine(LoadText());
}

IEnumerator LoadText()
	{
		string path = "http://172.27.35.1/Others/mytext.txt";
		WWW asset = new WWW(path);
		yield return asset;
		AssetBundle bundle = asset.assetBundle;
		Debug.Log(bundle);
		TextAsset textasset  =  bundle.LoadAsset("mytext",typeof(TextAsset)) as      TextAsset;
		mytext.text = textasset.text;
		bundle.Unload(false);
		asset.Dispose();
	}

}

 我这个是直接把txt文本放到了AssetBundle包中。然后放到web服务器上 www获取的。然后就这样吧。比较简单毕竟我也是初学者。

posted on 2015-12-21 17:16  萨瓦迪卡麦兜兜  阅读(1125)  评论(0编辑  收藏  举报

导航