tile2unity

来源:互联网 发布:网络机顶刷机软件下载 编辑:程序博客网 时间:2024/06/05 21:10

现在的项目使用Tiled软件编辑游戏地图,并通过第三方插件Tiled2Unity将地图文件解析到Unity,插件自动转换为相应的碰撞信息。




但是地图不可能只有一个,也就是说会编很多很多地图文件,但是如果因为疏忽想修改地图文件的内容,比如图层信息、参数或者碰撞等,就要把所有的地图文件全部修改一遍,一个个导入到unity特别的费时间,那么有没有一个工具批量导入到unity呢?这时候我想到了命令行工具,Tiled2Unity也支持命令行工具。


先看看最终效果:


1、先将调用命令行封装成一个函数,command则是文件名,如svn则会在环境变量PATH中的所有路径下查找名称为svn的文件文件进行执行,同样也可以写成完整路径如:F:\AA\bb.exe,argument则是参数
[csharp] view plain copy
  1. public static void ProcessCommand(string command,string argument){  
  2.         System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(command);  
  3.         info.Arguments = argument;  
  4.         info.CreateNoWindow = false;  
  5.         info.ErrorDialog = true;  
  6.         info.UseShellExecute = true;  
  7.           
  8.         if(info.UseShellExecute){  
  9.             info.RedirectStandardOutput = false;  
  10.             info.RedirectStandardError = false;  
  11.             info.RedirectStandardInput = false;  
  12.         } else{  
  13.             info.RedirectStandardOutput = true;  
  14.             info.RedirectStandardError = true;  
  15.             info.RedirectStandardInput = true;  
  16.             info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;  
  17.             info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;  
  18.         }  
  19.           
  20.         System.Diagnostics.Process process = System.Diagnostics.Process.Start(info);  
  21.           
  22.         if(!info.UseShellExecute){  
  23.             Debug.Log(process.StandardOutput);  
  24.             Debug.Log(process.StandardError);  
  25.         }  
  26.           
  27.         process.WaitForExit();  
  28.         process.Close();  
  29.     }  
2、调用Tiled2Unity软件,并传入参数,则自动打开Tiled2Unity软件进行导出,并发送到unity
[csharp] view plain copy
  1. ReimportMap("Tile文件TMX路径");//换成TMX路径  
[csharp] view plain copy
  1. static void ReimportMap(string path){  
  2.         string exportPath = Application.dataPath + "/Tiled2Unity";  
  3.         string arg = "-a -s=0.01 " + path + " " + exportPath;  
  4.         ProcessCommand ("Tiled2Unity安装路径/Tiled2Unity.exe", arg);//换成Tiled2Unity的安装路径  
  5.         AssetDatabase.Refresh ();  
  6.     }  
原创粉丝点击