unity基础开发----常用代码Unity中解析XML

前端之家收集整理的这篇文章主要介绍了unity基础开发----常用代码Unity中解析XML前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
C#代码
using UnityEngine;
using System.Collections;
using System.Xml;

public class NewBehavIoUrScript : MonoBehavIoUr {

	// Use this for initialization
	void Start () {
       // print(Application.dataPath);
        string url = Application.dataPath + "/test.xml";

        XmlDocument xmldoc = new XmlDocument();

        xmldoc.Load(url);

        //读取方式
        XmlNode root = xmldoc.SelectSingleNode("datas");

        if (root != null)
        {
            XmlNodeList nodelist = root.ChildNodes;
            foreach (XmlNode node in nodelist)
            {

                XmlElement xmlelement = (XmlElement)node;
                
               
                if (xmlelement.GetAttribute("equipCondition") == "2")
                {
                    print("+++++++++++++++++++++++++++++++++++++++++++++++++");
                    break;
                }
            }
        }        

       
	}
	
	// Update is called once per frame
	void Update () {
	
	}
    //
  
}

xml代码

<?xml version="1.0" encoding="UTF-8"?>
<datas>
 <data skillID="1001" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1002" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1003" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1004" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1005" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1006" skillType="1" skillName="一击必杀" equipCondition="0" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
 <data skillID="1007" skillType="1" skillName="一击必杀" equipCondition="2" learnCondition="0" learnMoney="0" skillLevel="1" skillDamage="0" angerCost="0" conjureTime="0" coolDownTime="0" scopeType="2" scope="4" effectID="0" effectRate="0" hitFlyDis="2" />
</datas>
备用: http://www.jb51.cc/article/p-qbfrbumq-bht.html

猜你在找的XML相关文章