using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
// 中文文件加载读取 //
public class TxTFiles : MonoBehaviour {
private string path = "";
// Use this for initialization
IEnumerator Start () {
/*
if(Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
{
path = Application.streamingAssetsPath;
}else
{
path = Application.dataPath;
}
*/
path = "file://" + Application.streamingAssetsPath;
TextAsset strings = (TextAsset)Resources.Load("Chinese");
yield return strings;
if(strings != null)
{
string[] stringArr = strings.text.Split("\n"[0]);
LoadFiles(stringArr);
}
}
private static Dictionary<string, string> AllTxtDic = new Dictionary<string, string>();
// 加载txt文件 //
public void LoadFiles(string[] stringArr)
{
int len = stringArr.Length;
for(int i = 0; i < len; i++)
{
string line = stringArr[i];
// 去掉空格 //
//line = line.Replace(" ","");
//line = line.Trim();
string[] lines = line.Split(new char[]{'='});
if(lines.Length == 2)
{
AllTxtDic.Add(lines[0].Trim(),lines[1].Trim());
}
}
}
public static string GetChineseString(string str)
{
string newstr = "";
try
{
newstr = AllTxtDic[str];
if(!AllTxtDic.ContainsKey(str))
{
newstr = "not have key" + AllTxtDic.Count.ToString();
}
}catch(Exception e)
{
return "";
}
return newstr;
}
}