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

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

分享到微博請遵守國家法律
孝感市| 紫金县| 隆昌县| 普宁市| 胶南市| 宣城市| 白河县| 石河子市| 华亭县| 蒙自县| 唐海县| 渝中区| 吐鲁番市| 酒泉市| 灵璧县| 泰安市| 城口县| 闽清县| 五河县| 大港区| 灵宝市| 宾阳县| 麻城市| 多伦县| 光山县| 霞浦县| 阜新市| 乐陵市| 鹤岗市| 邳州市| 北川| 兴隆县| 松溪县| 南涧| 海淀区| 五常市| 炎陵县| 濉溪县| 澄城县| 涪陵区| 横山县|