当前位置: 首页 > news >正文

做百度网站多少钱昭通建设局网站

做百度网站多少钱,昭通建设局网站,网站建设合同是否交纳印花税,人事处网站开发文献综述TexturePacker是一款非常牛逼的打图集软件,是一款收费软件。这是它的官网:https://www.codeandweb.com/texturepacker,大家可以下到最新版本。即便如此,网上还是有很多破解版的(虽然不是最新版的)&#xff…

TexturePacker是一款非常牛逼的打图集软件,是一款收费软件。这是它的官网:https://www.codeandweb.com/texturepacker,大家可以下到最新版本。即便如此,网上还是有很多破解版的(虽然不是最新版的),但是已经够用了。
其实Unity本身也有图集打包功能,但Unity并不想让开发者知道图集这个概念。开发的过程中,如果你不想知道图集的存在,Unity完全可以帮你隐藏得很深,但其实它还在帮你打图集。对于这种打图集方式,我很不放心。我还是想像传统那样的自己打图集,并且能看到打好的图集在哪里,长什么样,但又能被Unity所识别,即在Unity里能用。那TP就可以派上用场了。这是我用的3.0.3版本的TP。大家可以到这里下载
:http://pan.baidu.com/s/1bgjlHs。关于TP的用法,本文并不做介绍。本文要做的就是利用TP的命令行来实现完全自动化的图集打包。
打开命令行工具并CD到TexturePacker的安装目录,输入 TexturePacker –help,会出现该版本的TP的一些命令行参数。
这里写图片描述
下面我们写代码来用上这些命令行参数。写代码之前先看看我们要打成图集的小图们:

这里写图片描述

好的,上代码:

#if UNITY_EDITOR
using UnityEngine;
using System.IO;
using UnityEditor;
using System.Text;
using System.Diagnostics;
public class CommandBuild : Editor
{[MenuItem("Tools/SpritesPacker/CommandBuild")]public static void BuildTexturePacker(){//选择并设置TP命令行的参数和参数值string commandText = " --sheet {0}.png --data {1}.xml --format sparrow --trim-mode None --pack-mode Best  --algorithm MaxRects --max-size 2048 --size-constraints POT  --disable-rotation --scale 1 {2}" ;string inputPath = string.Format ("{0}/Images", Application.dataPath);//小图目录string outputPath = string.Format ("{0}/TexturePacker", Application.dataPath);//用TP打包好的图集存放目录string[] imagePath = Directory.GetDirectories (inputPath); for (int i = 0; i < imagePath.Length; i++) {UnityEngine.Debug.Log (imagePath [i]);StringBuilder sb = new StringBuilder("");string[] fileName = Directory.GetFiles(imagePath[i]);for (int j = 0; j < fileName.Length; j++){string extenstion = Path.GetExtension(fileName[j]);if (extenstion == ".png"){sb.Append(fileName[j]);sb.Append("  ");}UnityEngine.Debug.Log("fileName [j]:" + fileName[j]);}string name = Path.GetFileName(imagePath [i]);string outputName = string.Format ("{0}/TexturePacker/{1}/{2}", Application.dataPath,name,name);string sheetName = string.Format("{0}/SheetsByTP/{1}", Application.dataPath, name);//执行命令行processCommand("D:\\Program Files (x86)\\CodeAndWeb\\TexturePacker\\bin\\TexturePacker.exe", string.Format(commandText, sheetName, sheetName, sb.ToString()));}AssetDatabase.Refresh();}private static void processCommand(string command, string argument){ProcessStartInfo start = new ProcessStartInfo(command);start.Arguments = argument;start.CreateNoWindow = false;start.ErrorDialog = true;start.UseShellExecute = false;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.UTF8;start.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;}Process p = Process.Start(start);if(!start.UseShellExecute){UnityEngine.Debug.Log(p.StandardOutput.ReadToEnd());UnityEngine.Debug.Log(p.StandardError.ReadToEnd());}p.WaitForExit();p.Close();}}
#endif

运行 Tools/SpritesPacker/CommandBuild,并查看SheetsByTP目录下打包好的图集:

这里写图片描述

发现得到了两个文件,一个就是打包好的大图,及一个XML格式的配置文件:
这里写图片描述

这里写图片描述

但这样子的图集,unity并不能用,还需要做进一步的处理。这里先说下原理。在Unity里,一张图片的格式很多

这里写图片描述

不同格式有着不同的用途(UGUI用的是Sprite的格式),当我们往Unity里导入图片时,这张图片是什么格式由TextureImporter类决定,大家可以去看看这个类的API。然后我们再在Unity里随便找到一张图片的 .meta文件,用你喜欢的文本编辑器打开它:

fileFormatVersion: 2
guid: 542eed357a373ac4186621aa69a5ae78
timeCreated: 1456884951
licenseType: Pro
TextureImporter:fileIDToRecycleName: {}serializedVersion: 2mipmaps:mipMapMode: 0enableMipMap: 1linearTexture: 0correctGamma: 0fadeOut: 0borderMipMap: 0mipMapFadeDistanceStart: 1mipMapFadeDistanceEnd: 3bumpmap:convertToNormalMap: 0externalNormalMap: 0heightScale: .25normalMapFilter: 0isReadable: 0grayScaleToAlpha: 0generateCubemap: 0cubemapConvolution: 0cubemapConvolutionSteps: 8cubemapConvolutionExponent: 1.5seamlessCubemap: 0textureFormat: -1maxTextureSize: 2048textureSettings:filterMode: -1aniso: -1mipBias: -1wrapMode: -1nPOTScale: 1lightmap: 0rGBM: 0compressionQuality: 50allowsAlphaSplitting: 0spriteMode: 0spriteExtrude: 1spriteMeshType: 1alignment: 0spritePivot: {x: .5, y: .5}spriteBorder: {x: 0, y: 0, z: 0, w: 0}spritePixelsToUnits: 100alphaIsTransparency: 0textureType: -1buildTargetSettings: []spriteSheet:sprites: []spritePackingTag: userData: assetBundleName: assetBundleVariant: 

里边有个spriteSheet的项,在 TextureImporter的API里对应
这里写图片描述

发现是一个SpriteMetaData的数组。在看看SpriteMetaData有什么

这里写图片描述

我们只要把这些信息填好就行。上代码:

#if UNITY_EDITOR
using UnityEngine;
using System;
using System.IO;
using UnityEditor;
using System.Collections.Generic;
using System.Xml;
public class MySpritesPacker : Editor
{[MenuItem("Tools/SpritesPacker/TexturePacker")]public static void BuildTexturePacker(){string inputPath = string.Format("{0}/SheetsByTP/", Application.dataPath);string[] imagePath = Directory.GetFiles(inputPath);foreach (string path in imagePath){if (Path.GetExtension(path) == ".png" || Path.GetExtension(path) == ".PNG"){string sheetPath = GetAssetPath(path);Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(sheetPath);Debug.Log(texture.name);string rootPath = string.Format("{0}/TexturePacker/{1}", Application.dataPath,texture.name);string pngPath = rootPath + "/" + texture.name + ".png";TextureImporter asetImp = null;Dictionary<string, Vector4> tIpterMap = new Dictionary<string,Vector4>();if (Directory.Exists(rootPath)){if(File.Exists(pngPath)){Debug.Log("exite: " + pngPath);asetImp = GetTextureIpter(pngPath);SaveBoreder(tIpterMap, asetImp);File.Delete(pngPath);}File.Copy(inputPath + texture.name + ".png", pngPath);}else{Directory.CreateDirectory(rootPath);File.Copy(inputPath + texture.name + ".png", pngPath);}AssetDatabase.Refresh();FileStream fs = new FileStream(inputPath + texture.name + ".xml", FileMode.Open);StreamReader sr = new StreamReader(fs);string jText = sr.ReadToEnd();fs.Close();sr.Close();XmlDocument xml = new XmlDocument();xml.LoadXml(jText);XmlNodeList elemList = xml.GetElementsByTagName("SubTexture");WriteMeta(elemList, texture.name, tIpterMap);}}AssetDatabase.Refresh();}//如果这张图集已经拉好了9宫格,需要先保存起来static void SaveBoreder(Dictionary<string,Vector4> tIpterMap,TextureImporter tIpter){for(int i = 0,size = tIpter.spritesheet.Length; i < size; i++){tIpterMap.Add(tIpter.spritesheet[i].name, tIpter.spritesheet[i].border);}}static TextureImporter GetTextureIpter(Texture2D texture){TextureImporter textureIpter = null;string impPath = AssetDatabase.GetAssetPath(texture);textureIpter = TextureImporter.GetAtPath(impPath) as TextureImporter;return textureIpter;}static TextureImporter GetTextureIpter(string path){TextureImporter textureIpter = null;Texture2D textureOrg = AssetDatabase.LoadAssetAtPath<Texture2D>(GetAssetPath(path));string impPath = AssetDatabase.GetAssetPath(textureOrg);textureIpter =  TextureImporter.GetAtPath(impPath) as TextureImporter;return textureIpter;}//写信息到SpritesSheet里static void WriteMeta(XmlNodeList elemList, string sheetName,Dictionary<string,Vector4> borders){string path = string.Format("Assets/TexturePacker/{0}/{1}.png", sheetName, sheetName);Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path);string impPath = AssetDatabase.GetAssetPath(texture);TextureImporter asetImp = TextureImporter.GetAtPath(impPath) as TextureImporter;SpriteMetaData[] metaData = new SpriteMetaData[elemList.Count];for (int i = 0, size = elemList.Count; i < size; i++){XmlElement node = (XmlElement)elemList.Item(i);Rect rect = new Rect();rect.x = int.Parse(node.GetAttribute("x"));rect.y = texture.height - int.Parse(node.GetAttribute("y")) - int.Parse(node.GetAttribute("height"));rect.width = int.Parse(node.GetAttribute("width"));rect.height = int.Parse(node.GetAttribute("height"));metaData[i].rect = rect;metaData[i].pivot = new Vector2(0.5f, 0.5f);metaData[i].name = node.GetAttribute("name");if (borders.ContainsKey(metaData[i].name)){metaData[i].border = borders[metaData[i].name];}}asetImp.spritesheet = metaData;asetImp.textureType = TextureImporterType.Sprite;asetImp.spriteImportMode = SpriteImportMode.Multiple;asetImp.mipmapEnabled = false;asetImp.SaveAndReimport();}static string GetAssetPath(string path){string[] seperator = { "Assets" };string p = "Assets" + path.Split(seperator, StringSplitOptions.RemoveEmptyEntries)[1];return p;}}internal class TextureIpter
{public string spriteName = "";public Vector4 border = new Vector4();public TextureIpter() { }public TextureIpter(string spriteName, Vector4 border){this.spriteName = spriteName;this.border = border;}
}
#endif

然后点击 Tools/SpritesPacker/TexturePacker,看看 TexturePacker文件夹,会发现

这里写图片描述

这里写图片描述

这样Unity就用了,为了验证能用,我们把原来的小图和在TP里打包的图集都删掉,然后创建一些Image,用上我们打包好的图集里的图片。
这里写图片描述

这里写图片描述

到此就成功地在Unity用上了用TP打包好的图集了。
图片用到的九宫格信息也在这里哦!

http://www.15wanjia.com/news/165936.html

相关文章:

  • 电子商务网站搭建方案山东省建设厅的网站
  • 东营的网站建设公司搜索引擎大全排行
  • 张家港企业做网站好的建筑设计网站
  • 公司网站建设空间精通网站建设 100%全能建站密码pdf
  • 企业开源建站系统百度多久收录网站
  • 自助建站 知乎嘉兴网站排名优化公司
  • 网站建设时如何建立客户信赖感wordpress网站怎么加速
  • 邯郸做外卖网站的公司020网站管理系统模板
  • 青岛谁家做网站附近最好的装修公司
  • 网站建设 文章加强校园网站建设方案
  • 免费网站建设垂询186 6159 6345catchy wordpress
  • 如何用自己电脑做网站服务器深圳网站建设定制开发超凡科技
  • 如何用ps做网站界面科技有限公司属于什么行业
  • 海南网站制作公司wordpress 主题改名
  • 高质量的赣州网站建设建筑设计资质查询平台
  • 网站建设的潜规则注册安全工程师准考证打印入口
  • 广告公司会建设网站吗wordpress卡片圆角
  • 外部链接链轮的建设对于网站提杭州网站设计公司有哪些
  • 商城建设网站开发做网站怎么插音频
  • 企业网站的建设的功能定位英文网站建设平台
  • 个人门户网站农业公司网站建设
  • 网站建设模版 优帮云王烨岚
  • 购物网站建设价格一览表网盘做网站空间
  • 选服务好的网站建设公司好看云在线网站模板下载 迅雷下载 迅雷下载地址
  • 中国工程建设交易信息网站做网站开发哪里可以接单
  • 广州高端网站设计做统计的网站吗
  • nginx 做网站wordpress媒体文件夹
  • 注册域名后怎么建站外贸如何建立网站
  • 宝安网站设计案例免费的ppt模板网站有哪些
  • 写网站开发代码wordpress 视差主题