init
This commit is contained in:
88
Assets/Editor/WI/FontChanger.cs
Normal file
88
Assets/Editor/WI/FontChanger.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace XED.UI
|
||||
{
|
||||
public class FontChanger : MonoBehaviour
|
||||
{
|
||||
private const string FONTPATH = "Assets/Font/Pretendard-Regular SDF.asset";
|
||||
private static string[] folderPath = { "Assets/Prefabs",
|
||||
"Assets/Resources/Prefabs"};
|
||||
|
||||
[MenuItem("Tools/Change Font/Hierarchy")]
|
||||
public static void ChangeFont_Hierarchy()
|
||||
{
|
||||
GameObject[] rootObj = SceneManager.GetActiveScene().GetRootGameObjects();
|
||||
|
||||
for (int i = 0; i < rootObj.Length; i++)
|
||||
{
|
||||
SetFont(rootObj[i]);
|
||||
}
|
||||
|
||||
Debug.Log("Font changed successfully");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Change Font/Prject")]
|
||||
public static void ChangeFont_Prject()
|
||||
{
|
||||
string[] allPrefabs = AssetDatabase.FindAssets("t:Prefab");
|
||||
|
||||
foreach (string guid in allPrefabs)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
|
||||
if (IsPathAllowed(path) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
||||
|
||||
if (prefab != null)
|
||||
{
|
||||
int missingCount = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(prefab);
|
||||
|
||||
// ´©¶ô ½ºÅ©¸³Æ® Á¦°Å
|
||||
if(missingCount > 0)
|
||||
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(prefab);
|
||||
|
||||
SetFont(prefab);
|
||||
|
||||
PrefabUtility.SavePrefabAsset(prefab);
|
||||
EditorUtility.SetDirty(prefab);
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log("Font changed successfully");
|
||||
}
|
||||
|
||||
private static void SetFont(GameObject obj)
|
||||
{
|
||||
Component[] componts = obj.transform.GetComponentsInChildren(typeof(TextMeshProUGUI), true);
|
||||
|
||||
foreach (TextMeshProUGUI text in componts)
|
||||
{
|
||||
text.font = AssetDatabase.LoadAssetAtPath<TMP_FontAsset>(FONTPATH);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsPathAllowed(string path)
|
||||
{
|
||||
foreach (string folder in folderPath)
|
||||
{
|
||||
if (path.StartsWith(folder))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user