PrefabTMPProBold.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEngine;
  2. using UnityEditor;
  3. using TMPro;
  4. using System.IO;
  5. public static class PrefabTMPProBold
  6. {
  7. [MenuItem("Çл»/Scene_TextForTMP/Ô¤ÖÆÌåTMP¼Ó´Ö", false)]
  8. public static void ChangeText()
  9. {
  10. StartChangeScripts();
  11. }
  12. private static void StartChangeScripts()
  13. {
  14. string[] prefabs = Directory.GetFiles("Assets", "*.prefab", SearchOption.AllDirectories);
  15. for (int i = 0; i < prefabs.Length; i++)
  16. {
  17. GameObject go = AssetDatabase.LoadAssetAtPath(prefabs[i], typeof(System.Object)) as GameObject;
  18. TextMeshProUGUI[] textList = go.GetComponentsInChildren<TextMeshProUGUI>();
  19. if (textList.Length > 0)
  20. {
  21. GameObject root = PrefabUtility.LoadPrefabContents(prefabs[i]);
  22. if (root)
  23. {
  24. TextMeshProUGUI[] list = root.GetComponentsInChildren<TextMeshProUGUI>(true);
  25. for (int j = 0; j < list.Length; j++)
  26. {
  27. list[j].fontStyle = FontStyles.Bold;
  28. }
  29. }
  30. PrefabUtility.SaveAsPrefabAsset(root, prefabs[i], out bool success);
  31. }
  32. }
  33. }
  34. }