我在我的Unity3D游戏中进行了分析,我意识到当我试图在设备上创建一个文件夹时,一些安卓设备会抛出这个Unity3D。
看看抛出异常的代码:
static void SaveToCache(Entry entry, byte[] bytes) {
if (entry.file != null) {
string path = Path.GetDirectoryName(entry.file);
try {
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
File.WriteAllBytes(entry.file, bytes);
} catch (Exception ex) {
Analytics.LogException(ex, "couldn't save to cache: " + path);
}
}
}
密码看起来对我很好,但也许我遗漏了什么.它不会扔到我的测试设备-我只有堆栈跟踪从我的分析。
更相关的代码是我如何构建路径:
static readonly char DirectorySeparator = Path.DirectorySeparatorChar;
static string BundleFile(string id, string languageCode) {
StringBuilder sb = new StringBuilder();
sb.Append(BundlePath());
sb.Append(id);
sb.Append("_");
sb.Append(languageCode.ToLower());
sb.Append(".json");
return sb.ToString();
}
static string BundlePath() {
StringBuilder sb = new StringBuilder();
sb.Append(Application.persistentDataPath);
sb.Append(DirectorySeparator);
sb.Append("bundles");
sb.Append(DirectorySeparator);
return sb.ToString();
}
如果有人有类似的问题,请告诉我。我不能依赖Application.persistentDataPath吗?是否有更好的方法为缓存文件构建路径?
发布于 2015-09-17 08:58:00
我通过编写一个用于处理android上持久数据路径的工具包来解决这个问题。这将检查写访问,甚至在磁盘空间耗尽时使用回退。
https://stackoverflow.com/questions/31172191
复制相似问题