Unity3D开发

您所在的位置:网站首页 unity上传图片 Unity3D开发

Unity3D开发

2023-03-28 10:11| 来源: 网络整理| 查看: 265

1.图片处理2.编辑器扩展代码3.效果4.说明

来自于:itsxwz通过导入一张图片到Unity,把图片上的字符分割,再通过脚本转换为适用的字体文件。(精灵格式的图片)

1.图片处理

图片:处理:

2.编辑器扩展代码/**R0-V1.0*Modify Date:2018-11-29*Modifier:ZoJet*Modify Reason:根据图片生成包含对应字符的字体文件*Modify Content:*/using System.IO;using UnityEditor;using UnityEngine;public class CreateFontBySprite : MonoBehaviour { [MenuItem("Tools/CreateFont")] private static void CreateFont() { if (Selection.objects == null || Selection.objects.Length == 0) { Debug.Log("No selected object or sharding atlas"); return; } Object o = Selection.objects[0]; if (o.GetType() != typeof(Texture2D)) { Debug.Log("The selected file is not a picture"); return; } string selectionPath = AssetDatabase.GetAssetPath(o); if (selectionPath.Contains("Resources")) { string selectionExt = Path.GetExtension(selectionPath); if (selectionExt.Length == 0) { return; } string loadPath = selectionPath.Remove(selectionPath.Length - selectionExt.Length); string fontPathName = loadPath + ".fontsettings"; string matPathName = loadPath + ".mat"; float lineSpace = 0.1f; loadPath = Path.GetFileNameWithoutExtension(selectionPath); Sprite[] sprites = Resources.LoadAll(loadPath); if (sprites.Length > 0) { Texture2D tex = o as Texture2D; Material mat = new Material(Shader.Find("GUI/Text Shader")); AssetDatabase.CreateAsset(mat, matPathName); mat.SetTexture("_MainTex", tex); Font font = new Font(); font.material = mat; AssetDatabase.CreateAsset(font, fontPathName); CharacterInfo[] characterInfo = new CharacterInfo[sprites.Length]; for (int i = 0; i lineSpace) { lineSpace = sprites[i].rect.height; } } for (int i = 0; i 0) { pivot = -lineSpace / 2 - spr.pivot.y; } else if (pivot


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3