PersistentDataPath文件在设备上不起作用,但在unity 3d中可以
本文关键字:unity 但在 3d 不起作用 文件 PersistentDataPath | 更新日期: 2023-09-27 17:57:49
xml.Load(Application.persistentDataPath+"/PlayerData.xml");
XmlNode root = xml.FirstChild;
root = xml.LastChild;
if(root.InnerText == "")
{
lnoInstance.EnlistAllLevels();
foreach(LevelNamesStatus lno in LevelLoadingArray )
{
XmlNode child = CreateNode(xml,lno.Lname,lno.winStatus,lno.playingStatus);
root.AppendChild(child);
}
}
else
{
if(LevelLoadingArray.Count!=0 && LevelLoadingArray.Count<=13)
{ LevelNamesStatus[] array = CtrlLLoadingA.LevelLoadingArray.ToArray();
foreach(LevelNamesStatus n in array)
{
// Debug.Log(n.Lname+n.playingStatus);
}
foreach(XmlNode xmn in root)
{
xmn.ChildNodes[0].InnerText = LevelLoadingArray[f].Lname;
xmn.ChildNodes[1].InnerText = LevelLoadingArray[f].winStatus.ToString();
xmn.ChildNodes[2].InnerText = LevelLoadingArray[f].playingStatus.ToString();
f++;
}
}
if( LevelLoadingArray.Count==0)
{
RefillArray(root);
}
}
xml.Save(Application.persistentDataPath+"/PlayerData.xml");
无法在persistentDataPath处获取xml文件。。它在unity 3d上运行良好,但设备或模拟器无法获取该xml文件。。StorageExceptError在运行时保留在设备上
建议不要在任何地方使用硬编码的'/'或''''字符。请尝试使用Path.DirectorySeparatorChar
(请参阅Unity文档(。
在这种情况下,它应该是:
xml.Load(Application.persistentDataPath + Path.DirectorySeparatorChar + "PlayerData.xml");
然后你可以确定,在所有类型的设备或平台上,至少路径是正确的。
Application.persistentDataPath根据您的写入访问设置有两个路径,您可以在构建设置>播放器设置>其他设置中找到它,默认情况下,它是内部的。意味着路径应该指向/data/data/com.your.appid/files,这仅用于开发,用户在没有root android设备的情况下无法找到这些文件。
如果您将写入访问设置为外部(SD卡(或将Write_EEXTERNAL_STORAGE权限添加到AndroidManifest.xml中,Application.persistentDataPath将指向SD卡的Android/file/com.your.appid/files。
我也有同样的问题,这个解决了!
http://answers.unity3d.com/questions/203852/how-to-access-persistent-data-path-in-android-phon.html