源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 line
1.9 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. public class ArtistFont : MonoBehaviour
  5. { public static void BatchCreateArtistFont()
  6. {
  7. string dirName = "";
  8. string fntname = EditorUtils.SelectObjectPathInfo(ref dirName).Split('.')[0];
  9. Debug.Log(fntname);
  10. Debug.Log(dirName);
  11. string fntFileName = dirName + fntname + ".fnt";
  12. Font CustomFont = new Font();
  13. {
  14. AssetDatabase.CreateAsset(CustomFont, dirName + fntname + ".fontsettings");
  15. AssetDatabase.SaveAssets();
  16. }
  17. TextAsset BMFontText = null;
  18. {
  19. BMFontText = AssetDatabase.LoadAssetAtPath(fntFileName, typeof(TextAsset)) as TextAsset;
  20. }
  21. BMFont mbFont = new BMFont();
  22. BMFontReader.Load(mbFont, BMFontText.name, BMFontText.bytes); // 借用NGUI封装的读取类
  23. CharacterInfo[] characterInfo = new CharacterInfo[mbFont.glyphs.Count];
  24. for (int i = 0; i < mbFont.glyphs.Count; i++)
  25. {
  26. BMGlyph bmInfo = mbFont.glyphs[i];
  27. CharacterInfo info = new CharacterInfo();
  28. info.index = bmInfo.index;
  29. info.uv.x = (float)bmInfo.x / (float)mbFont.texWidth;
  30. info.uv.y = 1 - (float)bmInfo.y / (float)mbFont.texHeight;
  31. info.uv.width = (float)bmInfo.width / (float)mbFont.texWidth;
  32. info.uv.height = -1f * (float)bmInfo.height / (float)mbFont.texHeight;
  33. info.vert.x = (float)bmInfo.offsetX;
  34. info.vert.y = (float)bmInfo.offsetY;
  35. info.vert.width = (float)bmInfo.width;
  36. info.vert.height = (float)bmInfo.height;
  37. info.width = (float)bmInfo.advance;
  38. characterInfo[i] = info;
  39. }
  40. CustomFont.characterInfo = characterInfo;
  41. string textureFilename = dirName + mbFont.spriteName + ".png";
  42. Material mat = null;
  43. {
  44. Shader shader = Shader.Find("Transparent/Diffuse");
  45. mat = new Material(shader);
  46. Texture tex = AssetDatabase.LoadAssetAtPath(textureFilename, typeof(Texture)) as Texture;
  47. mat.SetTexture("_MainTex", tex);
  48. AssetDatabase.CreateAsset(mat, dirName + fntname + ".mat");
  49. AssetDatabase.SaveAssets();
  50. }
  51. CustomFont.material = mat;
  52. }
  53. }