在项目中遇到 需要将一些信息根据玩家走向 存储到数据 并展示出来
玩家死亡信息(死亡地区 死亡者 死亡原因 武力值) 包含多个信息
并且需要显示玩家的死亡记录 我这里选择了xml的读写方法
//主要包含三部分功能 创建xml 添加xml 读取xml
话不多说 上代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
using System.IO;
//一定要引用命名空间
public class XmlTool : MonoBehaviour {
//创建xml 名单id 死亡地区land 死亡者name 死亡原因whydead 武力值froce
void CreateXML(string id,string land,string name, string whydead, string froce)
{
string path = Application.streamingAssetsPath + "/Tomb.xml";
Debug.Log(path);
if (!File.Exists(path))
{
//创建
XmlDocument xml = new XmlDocument();
//创建最上一层的节点。
XmlElement root = xml.CreateElement("死亡名单");
//创建子节点
XmlElement element = xml.CreateElement("名单"+id);
//设置节点的属性
element.SetAttribute("land", land);
element.SetAttribute("name", name);
element.SetAttrib