XMLファイルの読み込み

using UnityEngine;
using System.Collections;
using System.Text;
using System.Xml;
using System.IO;

public class TMXLoader {
   public void Load(string fLevel) {
       TextAsset tmx = Resources.Load (fLevel) as TextAsset;
       // XML解析開始
       XmlDocument xmlDoc = new XmlDocument();
       xmlDoc.LoadXml (tmx.text);
       XmlNodeList mapList = xmlDoc.GetElementsByTagName("map");
       foreach(XmlNode map in mapList) {
           XmlNodeList childList = map.ChildNodes;
           foreach(XmlNode child in childList) {
               // 属性を取得
               XmlAttributeCollection attrs = child.Attributes;
               int w = int.Parse(attrs.GetNamedItem("width").Value); // 幅を取得.
               int h = int.Parse(attrs.GetNamedItem("height").Value); // 高さを取得.

タグ:

unity
最終更新:2015年04月05日 17:48