我是Unity开发的新手。我尝试编写使用Text Asset加载.txt文件的简单应用。它可以统一工作,但无法在android apk中加载。以下方法读取包含用户级别数据的文本文件。
private List<int[,]> LoadLevelsData()
{
TextAsset text = Resources.Load("levels") as TextAsset;
string[] rows = text.text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
List<int[,]> levelsData = new List<int[,]>();
int[,] currentLevel = new int[maxRowCount, maxColCount];
int currentRow = 0;
for (int row = 0; row < rows.Length; row++)
{
string line = rows[row];
if (line.IndexOf("--") == -1)
{
string[] bricks = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int col = 0; col < bricks.Length; col++)
{
currentLevel[currentRow, col] = int.Parse(bricks[col]);
}
currentRow++;
}
else
{
currentRow = 0;
levelsData.Add(currentLevel);
currentLevel = new int[maxRowCount, maxColCount];
}
}
return levelsData;
}