BFMenuTool.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4. namespace litefeel
  5. {
  6. public class BFMenuTool
  7. {
  8. [MenuItem("Assets/Bitmap Font/Rebuild Bitmap Font", true)]
  9. public static bool CheckRebuildFont()
  10. {
  11. if (EditorApplication.isPlaying) return false;
  12. TextAsset selected = Selection.activeObject as TextAsset;
  13. if (selected == null) return false;
  14. return BFImporter.IsFnt(AssetDatabase.GetAssetPath(selected));
  15. }
  16. [MenuItem("Assets/Bitmap Font/Rebuild Bitmap Font")]
  17. public static void RebuildFont()
  18. {
  19. TextAsset selected = Selection.activeObject as TextAsset;
  20. BFImporter.DoImportBitmapFont(AssetDatabase.GetAssetPath(selected));
  21. }
  22. [MenuItem("Assets/Bitmap Font/Rebuild All Bitmap Font", true)]
  23. public static bool CheckRebuildAllFont()
  24. {
  25. return !EditorApplication.isPlaying;
  26. }
  27. [MenuItem("Assets/Bitmap Font/Rebuild All Bitmap Font")]
  28. public static void RebuildAllFont()
  29. {
  30. string dataPath = Application.dataPath;
  31. int startPos = dataPath.Length - "Assets".Length;
  32. string[] files = Directory.GetFiles(Application.dataPath, "*.fnt", SearchOption.AllDirectories);
  33. for (int i = 0; i < files.Length; i++)
  34. {
  35. BFImporter.DoImportBitmapFont(files[i].Substring(startPos));
  36. }
  37. }
  38. }
  39. }