无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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)讀取游戲存檔的評論 (共 條)

分享到微博請遵守國家法律
广安市| 洛宁县| 芜湖县| 凤阳县| 体育| 永昌县| 塔城市| 礼泉县| 江川县| 陕西省| 郯城县| 宁河县| 资兴市| 芷江| 嘉荫县| 都江堰市| 巴中市| 紫云| 临城县| 垦利县| 长顺县| 星子县| 内江市| 米脂县| 增城市| 精河县| 余姚市| 许昌县| 巴中市| 高阳县| 如东县| 江安县| 土默特右旗| 咸丰县| 新邵县| 兴宁市| 临颍县| 内黄县| 瑞安市| 海兴县| 山阳县|