Bootstrap

Unity 制作数字图片字体

一键制作数字图片字体
切割数字图片sprite,例如一张0-9排成一列的图片,切割成10张图
切割好之后将此sprite放入Resources文件夹下 , 鼠标点击选择此图片
然后通过菜单窗口点Create_Font开始制作
在这里插入图片描述

  • 源码:


#if UNITY_EDITOR



using UnityEngine;

using UnityEditor;

using System.Collections;

//本方法是通过裁切的sprite导出字体文件,裁切使用的是unity自带的sprite editor,方便操作。  

//另外,裁切之后,每个sprite的名字的最后一个字符对应了ascii码的编码,比如:  

//0: 我们只要将sprite的名字命名成xxx0,就可以了!  

//由于使用到的了sprite加载,所以字体图片请放在Resources目录下面,等制作完毕,再把他们放到fonts文件夹或者其他文件夹中即可。  



namespace _GameScripts{



public class FontMaker

{

    [MenuItem("GameTools/Create_Font")]

    static void CreateMyFontSprite()

    {

        if (Selection.objects == null) return;

        if (Selection.objects.Length == 0)

        {

            Debug.LogWarning("没有选中Sprite文件,需要将Sprite Mode设置成Multiple,切分好,并且以以名字的最后一个字符当做ascii码");

            return;

        }

        string resoursePath = "Resources";

        Object o = Selection.objects[0];

        if (o.GetType() != typeof(Texture2D))

        {

            Debug.LogWarning("选中的并不是图片文件");

            return;

        }

        string selectionPath = AssetDatabase.GetAssetPath(o);

        if
;