//注意:要读取的文件的编码类型要为utf-8,不然会出现中文乱码或者直接不显示,如果是其它编码方式可以把文件
//另保存为utf-8的格式
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class Texts : MonoBehaviour
{
//public Text texts;
public string Mytxt; //存放文本内容
private string[] strArray;//声明一个字符串数组
private List<string> list;//声明一个字符串集合
/// </summary>
void Start()
{
// texts.text = Resources.Load("Mytext").ToString();
string path = "file://" + Application.streamingAssetsPath + "/" + "角色介绍.txt";
Debug.Log(path);
StartCoroutine(DownLoadTxT(path));
}
IEnumerator DownLoadTxT(string path)
{
WWW www = new WWW(path);
yield return www;
if (www.isDone)
{
//读取
Mytxt = www.text;
//分割
string str = Mytxt;
strArray = str.Split('@');
list = strArray.ToList();
for (int i = 0; i < list.Count; i++)
{
Debug.Log(list[i]);
}
//Text texts = transform.GetComponent<Text>();
//texts.text = www.text;
}
}
public void DuQuTxt(int a)
{
for (int i = 0; i < list.Count; i++)
{
Debug.Log(list[a]);
}
}
}