最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

【Unity開發(fā)教程】從零開始開發(fā)i wanna系列游戲(3)讀取游戲存檔

2023-09-03 01:37 作者:薔薇對你說晚安  | 我要投稿

太陽戰(zhàn)士索拉爾來啦,感覺unity有個bug,路徑設(shè)置對了依然會找不到,不如直接公開,把data文件拖進(jìn)去using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using System.Xml;


public class ResourceRvc : MonoBehaviour

{

public static ResourceRvc Instance; // 單例

public XmlDocument dataDocument; // 用于存儲XML文檔

public XmlNodeList dataNodeList; // 用于存儲XML節(jié)點列表

public TextAsset xmlFile; // 在Inspector面板中手動設(shè)置


public void Initsvc()

{

Instance = this; // 初始化單例

InitSaveDate(); // 初始化存檔數(shù)據(jù)

}


private void InitSaveDate()

{

dataDocument = new XmlDocument(); // 創(chuàng)建新的XML文檔

dataDocument.LoadXml(xmlFile.text); // 加載XML文件內(nèi)容

dataNodeList = dataDocument.SelectSingleNode("data").ChildNodes; // 獲取"data"節(jié)點的所有子節(jié)點

}


public struct SaveData // 存檔數(shù)據(jù)結(jié)構(gòu)

{

public string state; // 狀態(tài)

public int deathCount; // 死亡次數(shù)

public string time; // 時間

public string savePosition; // 存檔位置

// public string 最好把角色的子集狀態(tài)也儲存

}

public SaveData GetSaveData(int dataChooseNum) // 獲取存檔數(shù)據(jù)

{

XmlElement element = (XmlElement)dataNodeList[dataChooseNum]; // 獲取指定索引的節(jié)點

SaveData saveData = new SaveData(); // 創(chuàng)建新的存檔數(shù)據(jù)

saveData.state = element.GetAttribute("state"); // 獲取狀態(tài)

saveData.deathCount = int.Parse(element.GetAttribute("death")); // 獲取死亡次數(shù)

saveData.time = element.GetAttribute("time"); // 獲取時間

saveData.savePosition = element.GetAttribute("save_position"); // 獲取存檔位置

return saveData; // 返回存檔數(shù)據(jù)

}

}

【Unity開發(fā)教程】從零開始開發(fā)i wanna系列游戲(3)讀取游戲存檔的評論 (共 條)

分享到微博請遵守國家法律
萝北县| 高尔夫| 麻城市| 奇台县| 长治县| 都昌县| 莲花县| 福建省| 山西省| 杨浦区| 洪洞县| 尼木县| 横峰县| 湖口县| 石狮市| 巴青县| 新丰县| 额敏县| 全州县| 曲阜市| 台东市| 岗巴县| 突泉县| 白城市| 庄河市| 东平县| 永顺县| 三江| 连云港市| 阳西县| 开江县| 息烽县| 武胜县| 茶陵县| 衡山县| 马关县| 营山县| 嵊泗县| 大化| 高台县| 都匀市|