Unity中在移動平臺讀寫配置文件注意事項
在window版時應(yīng)該不會有太大問題這里就不敘述了
直接說在移動端時需要注意的
一、文件路徑
文件路徑網(wǎng)上已經(jīng)很多介紹了,這里就簡單的說下
參考地址:https://blog.csdn.net/wangshipeng409/article/details/93046648
1、Resources路徑
Resources文件夾下的資源不管是否有用,全部會打包進.apk或者.ipa,并且打包時會將里面的資源壓縮處理。加載方法是Resources.Load(文件名),需要注意:文件名不包括擴展名,打包后這個文件夾下的東西只能讀不能寫
2、application.dataPath路徑 這個返回的是程序的數(shù)據(jù)文件所在文件夾的路徑,但是在移動端它是完全沒用。
3、application.streamingAssetsPath路徑
這個用返回路徑為相對路徑,適合設(shè)置一些外部數(shù)據(jù)文件的路徑。在Unity工程的Assets目錄下起一個名為“StreamingAssets”的文件夾即可,然后用application.streamingAssetsPath訪問,這個文件夾中的資源在打包時會原封不動的打包進去,不會壓縮,在PC/MAC中可實現(xiàn)對文件的“增刪改查”等操作,但在移動端是一個只讀路徑。不能寫入
4、application.persistentDataPath路徑
這個返回一個持久化數(shù)據(jù)存儲目錄的路徑,可以在此路徑下存儲一些持久化的數(shù)據(jù)文件。這個路徑可讀、可寫,但是只能在程序運行時才能讀寫操作,不能提前將數(shù)據(jù)放入這個路徑。注意:如果在Android設(shè)置保存在沙盒中,那么就必須root以后才能用電腦取出文件,因此建議寫入sdcard里。一般情況下,建議將獲得的文件保存在這個路徑下,例如可以從StreamingAsset中讀取的二進制文件或者從AssetBundle讀取的文件寫入PersistentDatapath。
5、application.temporaryCachePath路徑
此屬性返回一個臨時數(shù)據(jù)的緩存目錄,跟application.persistentDataPath類似,但是在IOS上不能被自動備份。
6、/sdcard/…路徑 表示Android手機的SD卡根目錄。
7、/storage/emulated/0/…路徑(這個路徑我查找了好久……) 表示Android手機的內(nèi)置存儲根目錄。
以上各路徑中的資源加載方式都可以用WWW類加載,但要注意各個平臺路徑需要加的訪問名稱,例如Android平臺的路徑前要加"jar:file://",其他平臺使用"file://"。以下是各路徑在各平臺中的具體位置信息:
Android平臺 application.dataPath : /data/app/xxx.xxx.xxx.apk
application.streamingAssetsPath :
jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
application.persistentDataPath : /data/data/xxx.xxx.xxx/files
application.temporaryCachePath : /data/data/xxx.xxx.xxx/cache IOS平臺
application.dataPath :
application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data
application.streamingAssetsPath :
application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw
application.persistentDataPath :
application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents
application.temporaryCachePath :
application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches
Windows Web Player application.dataPath : file:///D:/MyGame/WebPlayer
(即導(dǎo)包后保存的文件夾,html文件所在文件夾) application.streamingAssetsPath :
application.persistentDataPath : application.temporaryCachePath :
二、不要寫在移動端不能執(zhí)行的代碼
例如下面這段代碼,下面這段是在resources文件夾里創(chuàng)建文件夾,但是一旦打包后resources文件夾就會被壓縮,就沒辦法執(zhí)行創(chuàng)建的事件。然后會導(dǎo)致這個腳本崩潰不在執(zhí)行本腳本以及后面的代碼。因此如果還在這腳本后面還寫有讀寫的代碼的話都不會執(zhí)行。因此有時沒有讀寫出數(shù)據(jù)其實并不是讀寫不了,而是因為腳本崩了導(dǎo)致沒有執(zhí)行讀寫代碼。
void Awake()
? ?{
? ? ? ?////判斷是否有文件夾如果沒有就創(chuàng)建文件夾
? ? ? ?//DirectoryInfo myResources = new DirectoryInfo(Application.dataPath + "/Resources");
? ? ? ?//DirectoryInfo myInfos = new DirectoryInfo(Application.dataPath + "/Resources/VariousInfos");
? ? ? ?//if (myResources.Exists)
? ? ? ?//{
? ? ? ?// ? ?if (!myInfos.Exists)
? ? ? ?// ? ?{
? ? ? ?// ? ? ? ?Directory.CreateDirectory(Application.dataPath + "/Resources/" + "VariousInfos");
? ? ? ?// ? ?}
? ? ? ?//}
? ? ? ?//else
? ? ? ?//{
? ? ? ?// ? ?Directory.CreateDirectory(Application.dataPath + "/" + "Resources");
? ? ? ?// ? ?Directory.CreateDirectory(Application.dataPath + "/Resources/" + "VariousInfos");
? ? ? ?//}
? ?}
三、讀寫權(quán)限問題
移動端都會有個讀寫權(quán)限問題,如果讀寫不了可以能是沒有讀寫權(quán)限
例如安卓平臺,對應(yīng)的要在Assets/Plugins/Android文件夾下放入權(quán)限的xml文件:AndroidManifest.xml
AndroidManifest.xml文件會在打包一次后在對應(yīng)的項目目錄下有個Temp/StagingArea文件下自動生成一個放到Plugins/Android文件夾中就行了,但是因為是自動生成的因此里面只會有一些默認的參數(shù),如果沒有自動生成的參數(shù)需要自行添加
參數(shù)參考鏈接:https://blog.csdn.net/linli1991/article/details/81531134
暫時就這么多,各位大佬如果還有補充的歡迎評論留言
下面附上我寫的通過.net讀和streamwriter寫入的代碼
(以下的讀寫xml代碼是能在安卓端正常運行讀寫的)
寫的不怎么好,請不要噴,里面有一些數(shù)據(jù)結(jié)構(gòu)是自定義的,我沒有整個腳本復(fù)制過來,如果復(fù)制我寫的函數(shù)代碼改寫時請自行改對應(yīng)的數(shù)據(jù)結(jié)構(gòu)
//將數(shù)據(jù)文件復(fù)制到Persistent路徑下
? ?public static void SetFileToPersistent()
? ?{
? ? ? ?FileInfo info = new FileInfo(Application.persistentDataPath + "/PlayerInfo.xml");
? ? ? ?if (!info.Exists)
? ? ? ?{
? ? ? ? ? ?try
? ? ? ? ? ?{
? ? ? ? ? ? ? ?TextAsset ts = Resources.Load("VariousInfos/PlayerInfo") as TextAsset;
? ? ? ? ? ? ? ?string content = ts.text;
? ? ? ? ? ? ? ?using (FileStream fs = new FileStream(Application.persistentDataPath + "/PlayerInfo.xml", FileMode.OpenOrCreate))
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ?sw.Write(content);
? ? ? ? ? ? ? ? ? ? ? ?sw.Close();
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?fs.Close();
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ? ? ?catch (Exception ex)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?Debug.Log(ex);
? ? ? ? ? ?}
? ? ? ?}
? ?}
//創(chuàng)建xml文件和根節(jié)點(文件名,路徑,根節(jié)點名)
? ?public ?bool CreateXml(string FileName = null, string FilePath = null, string RootName = null, bool IsUseXmlSave = false)
? ?{
? ? ? ?if (FileName == null) FileName = "PlayerInfo.xml";
? ? ? ?if (FilePath == null) FilePath = Application.persistentDataPath + "/";
? ? ? ?if (RootName == null) RootName = "PlayerInfoDatas";
? ? ? ?if (!File.Exists(FilePath + FileName))
? ? ? ?{
? ? ? ? ? ?XmlDocument xml = new XmlDocument();
? ? ? ? ? ?XmlElement root = xml.CreateElement(RootName);
? ? ? ? ? ?xml.AppendChild(root);
? ? ? ? ? ?//保存xml文件
? ? ? ? ? ?if (IsUseXmlSave)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?xml.Save(FilePath+FileName);
? ? ? ? ? ?}
? ? ? ? ? ?else
? ? ? ? ? ?{
? ? ? ? ? ? ? ?using (FileStream fs = new FileStream(FilePath + FileName, FileMode.OpenOrCreate))
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ?sw.Write(xml.OuterXml);
? ? ? ? ? ? ? ? ? ? ? ?sw.Close();
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?fs.Close();
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ? ? ?return true;
? ? ? ?}
? ? ? ?return false;
? ?}
//添加節(jié)點(玩家金幣,關(guān)卡Id,是否解鎖,擁有的圖片碎片數(shù)量,一共的圖片碎片數(shù)量,文件名,文件路徑,根節(jié)點名)
? ?public ?bool AddPlayerDataToXml(int PlayerGold = 0, bool IsRefreshItem = false, int TipsItems = 0, int MaxTipsItems = 3, int RefreshItemTime = 1800, string SaveTime = null, bool IsFirstGetChip = true, int LevelId = 1, bool IsUnlock = false, int OwnedImageChipNumber = 0, int MaxImageChipNumber = 1,bool IsShowChipTipps=false, int PlayGameNumber=0,string FileName = null, string FilePath = null, string RootName = null,bool IsUseXmlSave= false)
? ?{
? ? ? ?if (FileName == null) FileName = "PlayerInfo.xml";
? ? ? ?if (FilePath == null) FilePath = Application.persistentDataPath + "/";
? ? ? ?if (RootName == null) RootName = "PlayerInfoDatas";
? ? ? ?if (SaveTime == null) SaveTime = System.DateTime.Now.ToString();
? ? ? ?if (IsRefreshItem == true && TipsItems <= 0) { TipsItems = MaxTipsItems; IsRefreshItem = false; }
? ? ? ?//有文件時
? ? ? ?if (File.Exists(FilePath + FileName))
? ? ? ?{
? ? ? ? ? ?try
? ? ? ? ? ?{
? ? ? ? ? ? ? ?//讀文件
? ? ? ? ? ? ? ?if (xml.OuterXml == null || xml.OuterXml == string.Empty)
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?XmlReaderSettings st = new XmlReaderSettings();
? ? ? ? ? ? ? ? ? ?st.IgnoreComments = true;
? ? ? ? ? ? ? ? ? ?XmlReader reader = XmlReader.Create(FilePath + FileName, st);
? ? ? ? ? ? ? ? ? ?xml.Load(reader);
? ? ? ? ? ? ? ? ? ?reader.Close();
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?//獲取根節(jié)點
? ? ? ? ? ? ? ?XmlNode root = xml.SelectSingleNode(RootName);
? ? ? ? ? ? ? ?//獲取根節(jié)點下的第一個節(jié)點
? ? ? ? ? ? ? ?XmlNode rootChild = root.FirstChild;
? ? ? ? ? ? ? ?XmlNodeList elementList = null;
? ? ? ? ? ? ? ?XmlElement element = (XmlElement)root.FirstChild;
? ? ? ? ? ? ? ?//判斷根節(jié)點下的第一個節(jié)點是否存在
? ? ? ? ? ? ? ?if (element != null)
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?element.SetAttribute("PlayerGold", PlayerGold.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("IsRefreshItem", IsRefreshItem.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("TipsItems", TipsItems.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("MaxTipsItems", MaxTipsItems.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("RefreshItemTime", RefreshItemTime.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("SaveTime", SaveTime);
? ? ? ? ? ? ? ? ? ?element.SetAttribute("IsFirstGetChip", IsFirstGetChip.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("IsShowChipTipps", IsShowChipTipps.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("PlayGameNumber", PlayGameNumber.ToString());
? ? ? ? ? ? ? ? ? ?elementList = rootChild.ChildNodes;
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?element = xml.CreateElement("PlayerDatas");
? ? ? ? ? ? ? ? ? ?element.SetAttribute("PlayerGold", PlayerGold.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("IsRefreshItem", IsRefreshItem.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("TipsItems", TipsItems.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("MaxTipsItems", MaxTipsItems.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("RefreshItemTime", RefreshItemTime.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("SaveTime", SaveTime);
? ? ? ? ? ? ? ? ? ?element.SetAttribute("IsFirstGetChip", IsFirstGetChip.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("IsShowChipTipps", IsShowChipTipps.ToString());
? ? ? ? ? ? ? ? ? ?element.SetAttribute("PlayGameNumber", PlayGameNumber.ToString());
? ? ? ? ? ? ? ? ? ?elementList = element.ChildNodes;
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?//獲取根節(jié)點下的第一個節(jié)點下的所有節(jié)點
? ? ? ? ? ? ? ?foreach (XmlElement child in elementList)
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?int id = 0; int.TryParse(child.GetAttribute("LevelId"), out id);
? ? ? ? ? ? ? ? ? ?if (id == LevelId)
? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ?child.SetAttribute("LevelId", LevelId.ToString());
? ? ? ? ? ? ? ? ? ? ? ?child.SetAttribute("IsUnlock", IsUnlock.ToString());
? ? ? ? ? ? ? ? ? ? ? ?child.SetAttribute("OwnedImageChipNumber", OwnedImageChipNumber.ToString());
? ? ? ? ? ? ? ? ? ? ? ?child.SetAttribute("MaxImageChipNumber", MaxImageChipNumber.ToString());
? ? ? ? ? ? ? ? ? ? ? ?//保存到XML
? ? ? ? ? ? ? ? ? ? ? ?if (IsUseXmlSave)
? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ?element.AppendChild(child);
? ? ? ? ? ? ? ? ? ? ? ? ? ?root.AppendChild(element);
? ? ? ? ? ? ? ? ? ? ? ? ? ?xml.AppendChild(root);
? ? ? ? ? ? ? ? ? ? ? ? ? ?xml.Save(FilePath + FileName);
? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ?DeleteXmlFile();
? ? ? ? ? ? ? ? ? ? ? ? ? ?using (FileStream fs = new FileStream(FilePath + FileName, FileMode.OpenOrCreate))
? ? ? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sw.Write(xml.OuterXml);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sw.Close();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?fs.Close();
? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?return true;
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?//當(dāng)根節(jié)點下的第一個節(jié)點下沒有對應(yīng)的節(jié)點時創(chuàng)建節(jié)點保存數(shù)據(jù)
? ? ? ? ? ? ? ?XmlElement elementchild = xml.CreateElement("LevelId");
? ? ? ? ? ? ? ?elementchild.SetAttribute("LevelId", LevelId.ToString());
? ? ? ? ? ? ? ?elementchild.SetAttribute("IsUnlock", IsUnlock.ToString());
? ? ? ? ? ? ? ?elementchild.SetAttribute("OwnedImageChipNumber", OwnedImageChipNumber.ToString());
? ? ? ? ? ? ? ?elementchild.SetAttribute("MaxImageChipNumber", MaxImageChipNumber.ToString());
? ? ? ? ? ? ? ?//保存到XML
? ? ? ? ? ? ? ?if (IsUseXmlSave)
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?element.AppendChild(elementchild);
? ? ? ? ? ? ? ? ? ?root.AppendChild(element);
? ? ? ? ? ? ? ? ? ?xml.AppendChild(root);
? ? ? ? ? ? ? ? ? ?xml.Save(FilePath + FileName);
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?DeleteXmlFile();
? ? ? ? ? ? ? ? ? ?using (FileStream fs = new FileStream(FilePath + FileName, FileMode.OpenOrCreate))
? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ?using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
? ? ? ? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ? ? ?sw.Write(xml.OuterXml);
? ? ? ? ? ? ? ? ? ? ? ? ? ?sw.Close();
? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?fs.Close();
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?return true;
? ? ? ? ? ?}
? ? ? ? ? ?catch (Exception ex)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?Debug.Log(ex);
? ? ? ? ? ? ? ?if (output != null)
? ? ? ? ? ? ? ? ? ?output.text = ex.ToString();
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?return false;
? ?}
//讀取Xml文件數(shù)據(jù)
? ?public bool ReadXml(ref PlayerInfo Datas, Text test=null, string FileName = null, string FilePath = null, string RootName = null)
? ?{
? ? ? ?try
? ? ? ?{
? ? ? ? ? ?if (FileName == null) FileName = "PlayerInfo.xml";
? ? ? ? ? ?if (FilePath == null) FilePath = Application.persistentDataPath + "/";
? ? ? ? ? ?if (RootName == null) RootName = "PlayerInfoDatas";
? ? ? ? ? ?//讀文件
? ? ? ? ? ?if (xml.OuterXml == null || xml.OuterXml == string.Empty)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?XmlReaderSettings st = new XmlReaderSettings();
? ? ? ? ? ? ? ?st.IgnoreComments = true;
? ? ? ? ? ? ? ?XmlReader reader = XmlReader.Create(FilePath + FileName, st);
? ? ? ? ? ? ? ?xml.Load(reader);
? ? ? ? ? ? ? ?reader.Close();
? ? ? ? ? ?}
? ? ? ? ? ?if (test != null)
? ? ? ? ? ? ? ?test.text = "runing this fun";
? ? ? ? ? ?XmlNode root = ?xml.SelectSingleNode(RootName);
? ? ? ? ? ?int.TryParse(root.FirstChild.Attributes.GetNamedItem("PlayerGold").Value, out Datas.PlayerGold);
? ? ? ? ? ?bool.TryParse(root.FirstChild.Attributes.GetNamedItem("IsRefreshItem").Value, out Datas.IsRefreshItem);
? ? ? ? ? ?int.TryParse(root.FirstChild.Attributes.GetNamedItem("TipsItems").Value, out Datas.TipsItems);
? ? ? ? ? ?int.TryParse(root.FirstChild.Attributes.GetNamedItem("MaxTipsItems").Value, out Datas.MaxTipsItems);
? ? ? ? ? ?int.TryParse(root.FirstChild.Attributes.GetNamedItem("RefreshItemTime").Value, out Datas.RefreshItemTime);
? ? ? ? ? ?System.DateTime.TryParse(root.FirstChild.Attributes.GetNamedItem("SaveTime").Value, out Datas.SaveTime);
? ? ? ? ? ?bool.TryParse(root.FirstChild.Attributes.GetNamedItem("IsFirstGetChip").Value, out Datas.IsFirstGetChip);
? ? ? ? ? ?bool.TryParse(root.FirstChild.Attributes.GetNamedItem("IsShowChipTipps").Value, out Datas.IsShowChipTipps);
? ? ? ? ? ?int.TryParse(root.FirstChild.Attributes.GetNamedItem("PlayGameNumber").Value, out Datas.PlayGameNumber);
? ? ? ? ? ?XmlNodeList elementList = root.FirstChild.ChildNodes;
? ? ? ? ? ?foreach (XmlElement child in elementList)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?LevelDataBase tempImageData = new LevelDataBase();
? ? ? ? ? ? ? ?int.TryParse(child.GetAttribute("LevelId"), out tempImageData.LevelId);
? ? ? ? ? ? ? ?bool.TryParse(child.GetAttribute("IsUnlock"), out tempImageData.IsUnlock);
? ? ? ? ? ? ? ?int.TryParse(child.GetAttribute("OwnedImageChipNumber"), out tempImageData.OwnedImageChipNumber);
? ? ? ? ? ? ? ?int.TryParse(child.GetAttribute("MaxImageChipNumber"), out tempImageData.MaxImageChipNumber);
? ? ? ? ? ? ? ?Datas.LevelDatas[tempImageData.LevelId] = tempImageData;
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?catch (Exception ex)
? ? ? ?{
? ? ? ? ? ?Debug.Log(ex);
? ? ? ? ? ?if (output != null)
? ? ? ? ? ? ? ?output.text = ex.ToString();
? ? ? ?}
? ? ? ?return true;
? ?}
? ?//刪除Xml文件
? ?public ?bool DeleteXmlFile(string FileName = null, string FilePath = null)
? ?{
? ? ? ?if (FileName == null) FileName = "PlayerInfo.xml";
? ? ? ?if (FilePath == null) FilePath = Application.persistentDataPath + "/";
? ? ? ?if (File.Exists(FilePath + FileName))
? ? ? ?{
? ? ? ? ? ?File.Delete(FilePath + FileName);
? ? ? ? ? ?return true;
? ? ? ?}
? ? ? ?else
? ? ? ?{
? ? ? ? ? ?return false;
? ? ? ?}
? ?}