unity TexturePacker自动打图集编辑器——NGUI

unity TexturePacker自动打图集编辑器

目前仅支持windows,手边没有mac没法做。实现方式是用C#调用Cmd用命令行进行打图集,如果选择的输出目录是unity内部则自动创建材质球和AtlasPrefab。并且自动设置图片格式。目前编辑器功能比较少够我在我的项目里面用了,代码也比较简单可自行添加,如有不懂可以留言交流。
使用前需要安装TexturePacker,并且需要添加到环境变量,可以在TexturePacker File >Install command line client中查看。
在这里插入图片描述
编辑器界面
参数介绍
XmlPath:本工具会保存上一次用的配置,记录到本地的一个xml里路径可以在代码里面改。
CmdPath:填写你的cmd路径即可,环境变量里有的话可以直接写cmd.exe。
ResourcesPath:存放需要打成图集的碎图文件夹。
OutPutPath:图集的输出路径,如果是unity内部路径则可以直接产生NGUI用的材质球和Atlas Prefab。
TexturePacker Config:TexturePacker里的几个设置项
Unity Import Config:图片导入到Unity里面的几个设置项
Labels:图片在Unity里面的标签可以为空
就是你
OutputName:输出的名字不能为空必须配置
SaveConfig:保存当前的配置到xml
编辑器中列出的几个设置项是我在手动打图集过程中,需要修改的。
贴出运行cmd的代码吧

private void RunTexturePacker()
{
	string command = "/k " + _resourcesRootPath +
			"&TexturePacker " + _data.ResourcesPath +
			" --format unity --opt " + _data.TextureFormat_TP.ToString()+
			" --size-constraints "	+_data.SizeConstraints_TP+
			roatation + ditherType +
			" --max-width " + _data.MaxSize_Width_TP+
			" --max-height " + _data.MaxSize_Heitht_TP+
			" --sheet \""+ _data.OutPutPath+"/"+_outputName+".png\" " +
			"--data \""+_data.OutPutPath+"/"+_outputName+".txt\""+
			"&exit";
	processCommand (_data.CmdPath, command);
}

private static void processCommand(string cmdPath, string argument)
{
		ProcessStartInfo start = new ProcessStartInfo(cmdPath);
		start.Arguments = argument;
		start.CreateNoWindow = true;  //是否显示cmd窗口
		start.ErrorDialog = true;
		start.UseShellExecute = false; //是否使用shell

		if(start.UseShellExecute)
		{
			start.RedirectStandardOutput = false;
			start.RedirectStandardError = false;
			start.RedirectStandardInput = false;
		}
		else
		{
			start.RedirectStandardOutput = true;
			start.RedirectStandardError = true;
			start.RedirectStandardInput = true;
			start.StandardOutputEncoding = System.Text.UTF8Encoding.Default;
			start.StandardErrorEncoding = System.Text.UTF8Encoding.Default;
		}

		Process p = Process.Start(start);
		//process.StandardInput.WriteLine(argument) //不知为何不好使
		if(!start.UseShellExecute)
		{
			UnityEngine.Debug.Log(start.StandardOutputEncoding);
			UnityEngine.Debug.Log(p.StandardOutput.ReadToEnd ());
			string error = p.StandardError.ReadToEnd ();
			if (string.IsNullOrEmpty (error) == false) 
			{
				UnityEngine.Debug.LogError(error);
			}
		}

		p.WaitForExit();
		p.Close();
}

需要注意的点就是命令前面需要加一个/k 也不知道为啥,然后如果用process.StandardInput.WriteLine(argument)这种方式写入命令,则会报错不是内部或外部命令,如有知道的请提示我下,谢谢了。
下载地址 https://download.csdn.net/download/daimou123/11287082
完毕。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值