Unity TextAsset不会在Android APK中加载

时间:2019-12-03 11:37:36

标签: c# android unity3d resources apk

我是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;
}

0 个答案:

没有答案