using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml; public class xml : MonoBehaviour {
public Transform steel; void Start ()
{
List<Vector3> list=translateTileMapToList (); addListToWin (list);
} List<Vector3> translateTileMapToList()
{
List<Vector3> list = new List<Vector3> (); XmlDocument xmlDoc = new XmlDocument ();
xmlDoc.Load ("Assets/2.xml");
XmlNode mapNode = xmlDoc.SelectSingleNode ("map"); // map
foreach (XmlNode layerNode in mapNode.ChildNodes)
{ //tileset layer if (layerNode.Name == "layer")
{
XmlElement layerElement = (XmlElement)layerNode;
string widthString = layerElement.GetAttribute ("width");
int width = System.Int32.Parse (widthString);
string heightString = layerElement.GetAttribute ("height");
int height = System.Int32.Parse (heightString);
//string height =(int) layerElement.GetAttribute ("height").ToString(); //data
foreach (XmlNode dataNode in ((XmlElement)layerNode).ChildNodes)
{
//tile
int number=0;
foreach (XmlNode tileNode in ((XmlElement)dataNode).ChildNodes)
{
XmlElement tileElement = (XmlElement)tileNode;
int x = number % width;
int y = height - number / height; string zString = tileElement.GetAttribute ("gid");
int z = System.Int32.Parse (zString); list.Add (new Vector3 (x, y, z)); number++; }
}
}
}
return list;
} void addListToWin (List<Vector3> list)
{ for (int i = 0; i < list.Count; i++)
{
if (list [i].z == 11) {
Instantiate (steel, new Vector3 (list[i].x * 32f / 100f, list[i].y * 32f / 100f, 0), Quaternion.identity);
}
} } }

unity 解析tmx 2的更多相关文章

  1. unity 解析tmx

    using UnityEngine; using System.Collections; using System.IO; using System.Xml; public class xml : M ...

  2. 【转】Unity 解析Json字符串

    http://blog.csdn.net/qq_15267341/article/details/52013190 LitJSON使用很简单,两个步骤: 1 将LitJSON.dll文件拖动到unit ...

  3. unity解析json的两种方式

    一直比较钟情于json,用来做数据交互,堪称完美!下面简单说一下unity使用C#脚本如何解析json数据吧. 一.写解析类,借助于JsonUtility.FromJson 直接给个例子吧 1.jso ...

  4. unity 解析xml

    using UnityEngine; using System.Collections; using System.IO; using System.Xml; public class xml : M ...

  5. Unity游戏数据用Json保存

    (一)关于路径 unity有几个关键的路径 (1).Application.dataPath 只读路径,就是工作目录的Assets路径 (2).Application.streamingAssetsP ...

  6. Unity学习笔记(3):获取对象

    在上一篇文章中(Unity映射注册)中概要介绍了Unity中的映射机制,本节主要介绍对象获取,包括默认获取,通过名称获取,获取全部对象,同时通过加载配置文件,然后再获取对象. 通过代码获取对象 方式1 ...

  7. IoC容器之Unity

    关于IoC.Unity见博友文章点击这里. 话不多说,上程序HelloUnity,程序采用VS2010,Unity2.1. 1.程序框架如下 2.类库HelloUnity.Objects,主要为实体类 ...

  8. Cocos2d-x源代码解析(1)——地图模块(1)

    cocos通过加载tiled 生成的tmx文件来生成游戏地图.本文主要分析cocos加载地图模块的源代码.   如图所看到的,地图加载模块由以上几个类组成. 对外的入口是类CCTMXTiledMap, ...

  9. Ioc 之 Unity的依赖注入

    Unity是微软官方提供的一个Ioc容器,用来实现依赖注入,减少代码之间的耦合程度.使用Unity实现Ioc方式有两种,一种是使用代码方式实现,一种是利用配置文件来实现. 我们先来看一下代码方式是如何 ...

随机推荐

  1. XMPP框架下微信项目总结(5)花名册获取(好友列表)

    ---->概念 ---->添加花名册 ps:添加花名册,启动: 客户端发送请求到服务器获取好友列表信息,同时在项目中创建数据表,并保存好友列表到数据表中. ---->获取服务器保存好 ...

  2. 数据结构之AVL树

    AVL树是高度平衡的而二叉树.它的特点是:AVL树中任何节点的两个子树的高度最大差别为1. 旋转 如果在AVL树中进行插入或删除节点后,可能导致AVL树失去平衡.这种失去平衡的可以概括为4种姿态:LL ...

  3. UISegmentedControl

    1. NSArray *segmentedArray = [[NSArray alloc]initWithObjects:@"1",@"2",@"3& ...

  4. HTML5 – 4.canvas

    1.绘制矩形 2.绘制圆形 3.绘制文字 4.保存文件 什么是 Canvas? HTML5 <canvas> 元素用于图形的绘制,通过脚本 (通常是JavaScript)来完成. < ...

  5. 与你相遇好幸运,async解决循环回调问题

    由于使用的sailsjs框架,用的是sailsjs自身带的ORm(就是waterline),ORM的默认数据库的返回值在回调里面. > arg是一个数组 count用来计数用 tmpArr临时存 ...

  6. win10下安装Ubuntu + 修复Ubuntu引导

    如何在已安装 Windows 10 的情况下安装 Linux(Ubuntu 15.04)双系统? - Microsoft Windows - 知乎http://www.zhihu.com/questi ...

  7. 【PHP&&FileIO】

    在程序员的眼中,文件不应当仅仅是一部电影.一首歌曲.一个pdf文件,它应该被视为一个文件夹,而我们所熟知的文件,应当是它的特例. 在web开发中,文件的上传和下载是文件变成的一个实际应用. 延续cru ...

  8. SQL分组和聚合(Grouping and Aggregates)

    这章应该是难点,也是成为SQL高手的必经之路. 注意有GROUP 语句时,WHERE和HAVING的场合. 前者用于检索前的条件过滤 . 后者用于检索出来结果之后的条件过滤. ========== ; ...

  9. 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)

    Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件,由于手动书写很容易出错,我们可以利用Mybatis-Generator来帮我们自动生成文件. 1.相关文 ...

  10. android 入门-Activity及 字体

    private Button sButton; private TextView mTextView; private Button fButton; ,,,,}; @Override protect ...