|
生成Sprite Asset
image
TexturePacker 生成 tpsheet、png
image
生成文件对比 json与 tpsheet,最终tpsheet中位置和大小数据为最终准确数据。
image
image
image
image
5.导出之后会遇到切割位置信息不对,这时候需要用tpsheet中的数据设置一次。
image
使用tpsheet 文件重新赋值(位置,大小等属性)
image
Open EditorSpriteAsset Window 代码(可以直接copy使用但是需要注意tpsheet路径)
using System.IO;using TMPro;using UnityEditor;using UnityEngine;using UnityEngine.TextCore;namespace CS{ public class EditorSpritesAsset : EditorWindow { [MenuItem("Tools/EditorSpritesAsset")] public static void ShowSceneWindows() { EditorWindow win = GetWindow(typeof(EditorSpritesAsset), false,"编辑图集",true); win.Show(); } private TMP_SpriteAsset mSprAss = null; private void OnGUI() { mSprAss = EditorGUILayout.ObjectField(mSprAss, typeof(TMP_SpriteAsset )) as TMP_SpriteAsset; if (GUILayout.Button("确定" , GUILayout.Width(50), GUILayout.Height(20))) { RefreshSpritesAsset(); } } private void EditorSpriteAsset() { //此处为tpsheet文件所在的路径,读取文件中的数据 string str = File.ReadAllText(Application.dataPath + "/TextMesh Pro/Sprites/"+mSprAss.name+".tpsheet"); string[] strArr = str.Split('\n'); int i = 0; GlyphRect glyphRectTmp = new GlyphRect(0, 0, 0, 0); GlyphMetrics glyphMetrics = new GlyphMetrics(); foreach (var item in strArr) { if (item.StartsWith("#") || item.StartsWith(":") || string.IsNullOrEmpty(item)|| item.StartsWith("\r")) { continue; } string[] strArr2 = item.Split(';'); glyphRectTmp.x = int.Parse(strArr2[1]); glyphRectTmp.y = int.Parse(strArr2[2]); glyphRectTmp.width = int.Parse(strArr2[3]); glyphRectTmp.height = int.Parse(strArr2[4]); mSprAss.spriteGlyphTable.glyphRect = glyphRectTmp; glyphMetrics = mSprAss.spriteGlyphTable.metrics; glyphMetrics.horizontalBearingX = 0; glyphMetrics.horizontalBearingY = int.Parse(strArr2[4])-5; mSprAss.spriteGlyphTable.metrics = glyphMetrics; i++; } } }}
image
image
8.最后找到TMP Settings 配置文件,将新生成的Sprite Asset 设置为默认。
image
9.直接设置图片名字就可以生效。
"You must earn 1 <sprite name="currency_diamond_big"/> character if you recruit 10 times" |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|