[英]Writing to Application.persistentDataPath on HoloLens 2 with Unity3D and accessing files afterward through device web portal
[英]PersistentDataPath file is not working on device but fine in unity 3d
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 有兩個基於您的寫入權限設置的路徑,您可以在 Build Setting > Player Setting > Other Settings 中找到它,默認情況下,它是 internal Only。 意味着路徑應該指向/data/data/com.your.appid/files,它僅用於開發,用戶在沒有root android設備的情況下無法找到這個文件。
如果您將寫入訪問權限設置為外部(SD 卡)或在 AndroidManifest.xml 中添加 WRITE_EXTERNAL_STORAGE 權限,則 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.