Advertisement

Unity 读取、编写和生成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 = 

全部评论 (0)

还没有任何评论哟~