配合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;