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. 手写代码自动实现自动布局,即Auto Layout的使用

    手写代码自动实现自动布局,即Auto Layout的使用,有需要的朋友可以参考下. 这里要注意几点: 对子视图的约束,若是基于父视图,要通过父视图去添加约束. 对子视图进行自动布局调整,首先对UIVi ...

  2. 动手动脑及java程序之用消息框进行数的运算

        动手动脑     自信成就人生 动手动脑1 ✿仔细阅读示例: EnumTest.java,运行它,分析运行结果? package demo; public class Test { publi ...

  3. codevs 1488GangGang的烦恼

    题目链接:http://codevs.cn/problem/1488/ 写个高精度大数运算就行 #include<cstdio> #include<iostream> #inc ...

  4. Python中如何读取xml的数据

    <?xml version="1.0" encoding="utf-8" ?> - <catalog> <maxid>4&l ...

  5. Localstorage本地存储兼容函数

    前言HTML5提供了本地存储的API:localstorage对象和sessionStorage对象,实现将数据存储到用户的电脑上.Web存储易于使用.支持大容量(但非无限量)数据同时存储,同时兼容当 ...

  6. PostgreSQL简单介绍

    自从MySQL被Oracle收购以后,PostgreSQL逐渐成为开源关系型数据库的首选. 本文介绍PostgreSQL的安装和基本用法,供初次使用者上手.以下内容基于Debian操作系统,其他操作系 ...

  7. oracle检查点队列(checkpoint queue)

    buffer cache CBC链 按地址链 LRU  干净buffer LRUW  脏buffer  按照冷热 checkpoint queue:链buffer,①链脏块②按buffer第一次脏的时 ...

  8. C# 使用 NPOI 库读写 Excel 文件

    NPOI 是开源的 POI 项目的.NET版,可以用来读写Excel,Word,PPT文件.在处理Excel文件上,NPOI 可以同时兼容 xls 和 xlsx.官网提供了一份 Examples,给出 ...

  9. Android之Adapter用法总结(转)

    Android之Adapter用法总结 1.概念 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的View(List View,Grid Vie ...

  10. PC端重置

    -PC 一,meta <!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta cha ...