unity 解析tmx 2
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的更多相关文章
- unity 解析tmx
using UnityEngine; using System.Collections; using System.IO; using System.Xml; public class xml : M ...
- 【转】Unity 解析Json字符串
http://blog.csdn.net/qq_15267341/article/details/52013190 LitJSON使用很简单,两个步骤: 1 将LitJSON.dll文件拖动到unit ...
- unity解析json的两种方式
一直比较钟情于json,用来做数据交互,堪称完美!下面简单说一下unity使用C#脚本如何解析json数据吧. 一.写解析类,借助于JsonUtility.FromJson 直接给个例子吧 1.jso ...
- unity 解析xml
using UnityEngine; using System.Collections; using System.IO; using System.Xml; public class xml : M ...
- Unity游戏数据用Json保存
(一)关于路径 unity有几个关键的路径 (1).Application.dataPath 只读路径,就是工作目录的Assets路径 (2).Application.streamingAssetsP ...
- Unity学习笔记(3):获取对象
在上一篇文章中(Unity映射注册)中概要介绍了Unity中的映射机制,本节主要介绍对象获取,包括默认获取,通过名称获取,获取全部对象,同时通过加载配置文件,然后再获取对象. 通过代码获取对象 方式1 ...
- IoC容器之Unity
关于IoC.Unity见博友文章点击这里. 话不多说,上程序HelloUnity,程序采用VS2010,Unity2.1. 1.程序框架如下 2.类库HelloUnity.Objects,主要为实体类 ...
- Cocos2d-x源代码解析(1)——地图模块(1)
cocos通过加载tiled 生成的tmx文件来生成游戏地图.本文主要分析cocos加载地图模块的源代码. 如图所看到的,地图加载模块由以上几个类组成. 对外的入口是类CCTMXTiledMap, ...
- Ioc 之 Unity的依赖注入
Unity是微软官方提供的一个Ioc容器,用来实现依赖注入,减少代码之间的耦合程度.使用Unity实现Ioc方式有两种,一种是使用代码方式实现,一种是利用配置文件来实现. 我们先来看一下代码方式是如何 ...
随机推荐
- Java动态代理一Proxy
什么是动态代理? 动态代理可以提供对另一个对象的访问,同时隐藏实际对象的具体事实.代理一般会实现它所表示的实际对象的接口.代理可以访问实际对象,但是延迟实现实际对象的部分功能,实际对象实现系统的实际功 ...
- java 学习笔记——网络(Socket)
阅读方法:将网页放大到200%. 如果你用过用过word应该知道按住ctrl键使用鼠标滚轮缩放.
- git 提交代码的流程
[root@ok-T IT-DOC]# ls hx-海星-wifi.rd web收藏.txt [root@ok-T IT-DOC]# git status -s ?? "web\346\22 ...
- Overview and Evaluation of Bluetooth Low Energy: An Emerging Low-Power Wireless Technology
转自:http://www.mdpi.com/1424-8220/12/9/11734/htm Sensors 2012, 12(9), 11734-11753; doi:10.3390/s12091 ...
- 谈谈Delphi中的类和对象4---类是一种对数据和操作高度的封装机制 && 类是一种代码重用机制
五.类是一种对数据和操作高度的封装机制 1)数据封装 unit Unit2; interface type TEmployee = class; private FName: String; publ ...
- 【转载】Pyqt QSplitter分割窗口
转载来自: http://blog.sina.com.cn/s/blog_4b5039210100h3ih.html 分割窗口在应用程序中经常用到,它可以灵活分布窗口布局,经常用于类似文件资源管理器的 ...
- 【131202】SQL
SELECT TOP 2 * FROM Persons SELECT *FROM PersonsWHERE ROWNUM <= 5 SELECT * FROM Persons WHERE C ...
- xml解析方法总结
==========================================xml文件<?xml version=”1.0″ encoding=”GB2312″?> <RES ...
- 深入理解JavaScript定时机制和定时器注意问题
容易欺骗别人感情的JavaScript定时器 JavaScript的setTimeout与setInterval是两个很容易欺骗别人感情的方法,因为我们开始常常以为调用了就会按既定的方式执行, 我想不 ...
- android 入门-关键词介绍
1.@SuppressLint("HandlerLeak") 2.synchronized详解 http://www.cnblogs.com/GnagWang/archive/20 ...