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方式有两种,一种是使用代码方式实现,一种是利用配置文件来实现. 我们先来看一下代码方式是如何 ...
随机推荐
- Codeforces Round #327 (Div. 2)B(逻辑)
B. Rebranding time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- DDD的思考
概述 DDD领域驱动设计,它是对面向对象的的分析和设计(OOAD,Object Orient Analysis Design)的一个补充,对技术框架进行了分层规划,同时对每个类进行了策略和类型划分.领 ...
- CentOS FTP基于虚拟用户的配置
详细可以看:http://www.linuxidc.com/Linux/2013-12/94242.htm 所谓虚拟用户就是没有使用真实的帐户,只是通过映射到真实帐户和设置权限的目的.虚拟用户不能登录 ...
- [LeetCode] Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- Python多版本共存之pyenv
经常遇到这样的情况: 系统自带的Python是2.6,自己需要Python 2.7中的某些特性: 系统自带的Python是2.x,自己需要Python 3.x: 此时需要在系统中安装多个Python, ...
- 快速熟悉python 下使用mysql(MySQLdb)
首先你需要安装上mysql和MySQLdb模块(当然还有其他模块可以用),这里我就略过了,如果遇到问题自行百度(或者评论在下面我可以帮忙看看) 这里简单记录一下自己使用的学习过程: 一.连接数据库 M ...
- [Liferay6.2]核心配置文件portal.properties
portal.properties是liferay中一个非常核心的配置文件.我们可以在liferay源代码或者解压liferay部署包中的portal-impl.jar中获得.以liferay6.2为 ...
- Codeforces Round #370 (Div. 2) D. Memory and Scores DP
D. Memory and Scores Memory and his friend Lexa are competing to get higher score in one popular c ...
- LeetCode——Reverse Integer(逆置一个整数)
问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321 Ha ...
- Action处理请求参数
第一种 :Action 本身作为model对象,通过成员setter封装 (属性驱动 ) 第一种方式:<br> <form action="${pageContext.re ...