自己写的BMFont导入工具,快速把图片转换为美术字体

这篇博客介绍了一种方法,通过ArtFontTool和FontTool类,结合BMFont工具,将图片转换为Unity项目的美术字体。工具帮助开发者快速处理图片并生成字体资源,包括替换精灵、加载和序列化字体数据。
摘要由CSDN通过智能技术生成

配合BMFont工具使用可以快速把图片转换为美术字,在项目中使用美术字体,需要准备一个材质球 一个空白字体,然后自己改一下路径,这三个脚本是分开的 ,先点art。

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;


public class ArtFontTool
{
    static Dictionary<Image, string> imageDic = null;
    [MenuItem("Font/Make ArtFont")]
    static public void GenAllFont()
    {
        imageDic = new Dictionary<Image, string>();
        string prefabs = Application.dataPath + "/BundleResources/UI/Prefabs/";
        foreach (var dir in Directory.GetFiles(prefabs,"*.prefab"))
        {
            ProcPrefab(dir.Substring(prefabs.Length));
        }
        AssetDatabase.SaveAssets();
    }

    static void ProcPrefab(string prefab)
    {
        Debug.Log("------------------------------------");
        Debug.Log(prefab);

        var prefabName = "Assets/BundleResources/UI/Prefabs/" + prefab;
        GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(prefabName);
        if(go == null)
        {
            return;
        }

        imageDic.Clear();
        Image[] imgs = go.GetComponentsInChildren<Image>(true);
        for(int i = 0; i < imgs.Length; ++i)
        {
            Image img = imgs[i];
            //var hash = img.mainTexture.imageContentsHash;
            //var sobj = new SerializedObject(img.sprite);
            Sprite s = img.sprite;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值