1.新建Canvas画布,在画布下面添加5个button按钮,创建XML、增加XML、更新XML、查看XML、删除XML

2.将脚本挂载到Canvas身上,并将Canvas拖到button按钮的OnClick属性上,再为不同按钮选择脚本中对应的方法
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using UnityEngine;
public class XMLTest : MonoBehaviour {
//创建XML
public void CreateXML()
{
string path = Application.dataPath + "/xmlData.xml";//创建xml生成的路径和xml文件名称
if (!File.Exists(path))
{
XmlDocument xmlDoc = new XmlDocument(); //创建文档
XmlNode xmlDeclaration= xmlDoc.CreateXmlDeclaration("1.0","utf-8",null);//节点设定,版本描述,编码设定
xmlDoc.AppendChild(xmlDeclaration);//向xml中加入描述信息
XmlNode root= xmlDoc.CreateElement("技能");//根节点
xmlDoc.AppendChild(root);
XmlElement skill1= xmlDoc.CreateElement("技能1");
skill1.SetAttribute("name", "乾坤大挪移");
skill1.SetAttribute("id", "1");
XmlNode hit= xmlDoc.CreateElement("hitDamage");
hit.InnerText = "100";
XmlNode player = xmlDoc.CreateElement("player");
player.InnerText = "阳顶天";
skil