【发布时间】:2018-08-03 15:07:23
【问题描述】:
我在 Unity 中为 android 制作了一个文字游戏应用程序,玩家必须从之前加载到游戏中的类别中找到一个单词。
我加载类别的方式是: 在 Assets 中有一个名为 Categories 的文件夹,我遍历该文件夹并将每个文本文件作为一个类别读取。
类别存储在字典中,其中键是文件的名称,值是文件的每一行作为数组元素。
它在 PC 上运行良好,但在 android 上没有运气。尝试将路径更改为 "公共字符串 categoriesDirectoryPath = Application.persistentDataPath +"Categories";"还是不行。
原始路径是“资产/类别”
使用文件值启动字典的代码是(发生在 GameManager 的 Awake() 上):
private Dictionary<string, string[]> createCategories(string directoryPath)
{
Dictionary<string, string[]> categories = new Dictionary<string, string[]>();
string[] categoryPaths = Directory.GetFiles(directoryPath);
foreach (string path in categoryPaths)
{
if (!path.EndsWith("meta")) {
Debug.Log(path);
string categoryName = Path.GetFileNameWithoutExtension(path);
Debug.Log(categoryName);
string[] categoryData = File.ReadAllLines(path).ToArray();
categories.Add(categoryName, categoryData);
}
}
return categories;
}
有没有办法在构建 APK 后迭代文件夹并读取 Assets/Categories 中的文本文件?
【问题讨论】:
标签: unity3d