【unity拓展】Unity3d通过Tiled2Unity批量导入Tile地图到unity

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




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


先看看最终效果:


1、先将调用命令行封装成一个函数,command则是文件名,如svn则会在环境变量PATH中的所有路径下查找名称为svn的文件文件进行执行,同样也可以写成完整路径如:F:\AA\bb.exe,argument则是参数
public static void ProcessCommand(string command,string argument){
		System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(command);
		info.Arguments = argument;
		info.CreateNoWindow = false;
		info.ErrorDialog = true;
		info.UseShellExecute = true;
		
		if(info.UseShellExecute){
			info.RedirectStandardOutput = false;
			info.RedirectStandardError = false;
			info.RedirectStandardInput = false;
		} else{
			info.RedirectStandardOutput = true;
			info.RedirectStandardError = true;
			info.RedirectStandardInput = true;
			info.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
			info.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
		}
		
		System.Diagnostics.Process process = System.Diagnostics.Process.Start(info);
		
		if(!info.UseShellExecute){
			Debug.Log(process.StandardOutput);
			Debug.Log(process.StandardError);
		}
		
		process.WaitForExit();
		process.Close();
	}
2、调用Tiled2Unity软件,并传入参数,则自动打开Tiled2Unity软件进行导出,并发送到unity
ReimportMap("Tile文件TMX路径");//换成TMX路径
static void ReimportMap(string path){
		string exportPath = Application.dataPath + "/Tiled2Unity";
		string arg = "-a -s=0.01 " + path + " " + exportPath;
		ProcessCommand ("Tiled2Unity安装路径/Tiled2Unity.exe", arg);//换成Tiled2Unity的安装路径
		AssetDatabase.Refresh ();
	}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼蛋-Felix

如果对你有用,可以请我喝杯可乐

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值