Unity 读写xml 创建 读取

本文介绍如何在Unity项目中利用XML文件存储玩家的死亡信息,包括死亡地区、死者、死亡原因和武力值等数据,并详细阐述了XML文件的创建、添加和读取过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在项目中遇到  需要将一些信息根据玩家走向 存储到数据 并展示出来

玩家死亡信息(死亡地区 死亡者 死亡原因 武力值)  包含多个信息

 并且需要显示玩家的死亡记录 我这里选择了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.SetAttribute("whydead", whydead);
element.SetAttribute("froce", froce);
/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值