为了统一游戏,我必须在iOS设备上保存一些本地数据。团结提供
Application.persistentDataPath以获取公共目录以保存数据。并在控制台上打印它,表明为iOS返回的路径是正确的,即iOS
因此,一个函数返回路径和其他检查目录是否存在,如果没有,它应该创建一个目录,但它创建的文件没有任何扩展名。这是我的密码
void savePose(Pose pose){
if (!Directory.Exists(PoseManager.poseDirectoryPath())){
Directory.CreateDirectory(PoseManager.poseDirectoryPath());
//Above line creates a file
//by the name of "SavedPoses" without any extension
}
// rest of the code goes here
}
static string poseDirectoryPath() {
return Path.Combine(Application.persistentDataPath,"SavedPoses");
}发布于 2016-10-06 13:30:09
可能的偷懒行为:
1.Path.Combine(Application.persistentDataPath,"SavedPoses");在savedPoses之前添加反斜杠,而其他则是正斜杠。也许这会在iOS上引起问题。尝试在没有Path.Combine函数的情况下连接原始字符串。
static string poseDirectoryPath() {
return Application.persistentDataPath + "/" + "SavedPoses";
}2.If Directory类不能正常工作,请使用DirectoryInfo类。
private void savePose(Pose pose)
{
DirectoryInfo posePath = new DirectoryInfo(PoseManager.poseDirectoryPath());
if (!posePath.Exists)
{
posePath.Create();
Debug.Log("Directory created!");
}
}
static string poseDirectoryPath()
{
return Path.Combine(Application.persistentDataPath, "SavedPoses");
}编辑
可能是iOS上的权限问题。
您可以在StreamingAssets目录中创建文件夹。您有读写此目录的权限。
访问它的一般方法是使用Application.streamingAssetsPath/。
在iOS上,也可以使用Application.dataPath + "/Raw"访问它。
在安卓系统上,它也可以用"jar:file://" + Application.dataPath + "!/assets/";访问,对于Windows和Mac也可以用Application.dataPath + "/StreamingAssets";访问。就用对你有用的那个吧。
对于你的问题,Application.dataPath + "/Raw"+"/SavedPoses";应该这么做。
https://stackoverflow.com/questions/39896730
复制相似问题