AssetBundle 빌드 시, Font가 번들에 포함 안되도록 스크립트로 처리하기
Unity 2021.3.47f1
----
Dynamic Font의 옵션에 Include Font Data가 체크 돼 있으면, AssetBundle 빌드 시 Font도 번들에 포함 되는 것 같다.
[참조] https://codingstarter.tistory.com/37
[Unity] AssetBundle & Addressable 폰트 중복 로드 문제
- UI를 번들에서 로드하도록 수정 했더니 메모리에 동일한 폰트가 중복으로 로드되는 현상이 발생 - 동일한 폰트여도 각 번들마다 개별적으로 로드되는 것으로 추정 - 폰트 에셋의 Include Font Data
codingstarter.tistory.com
AssetBundle 빌드는 스크립트로 하기 때문에 위 참조 링크의 내용대로
AssetBundle 빌드 전, IncludeFontData를 false로 하고,
AssetBundle 빌드 후, IncludeFontData를 true로 되돌리도록 처리했다.
기본적으로 Dynamic Font의 폴더를 지정은 해야되지만 폴더의 하위는 모두 훑어서 ttf파일은 모두 처리하도록 해뒀다.
/// <summary>
/// Dynamic Font Path
/// 사용하는 Dynamic Font를 AssetBundle 빌드 할 때 포함 안되도록
/// AssetBundle 빌드 시, false 했다가 되돌리기 위해 사용
/// [주의] 실제 사용하는 다이나믹 폰트 Folder Path 체크 필요
/// </summary>
private static string m_strDynamicFontFolderPath = "Assets/Fonts/Dynamic";
public static void ProcessIncludeFontData(string _strTargetDirectory, bool _bActive)
{
if (false == Directory.Exists(_strTargetDirectory))
return;
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(_strTargetDirectory);
foreach (System.IO.FileInfo fi in di.GetFiles())
{
if (fi.Extension.ToLower().CompareTo(".ttf") == 0)
{
//string strFileNameOnly = fi.Name.Substring(0, fi.Name.Length - 4);
string strFullFilePath = fi.FullName.Replace("\\", "/");
Debug.LogWarningFormat("[strFullFilePath] {0}", strFullFilePath);
// 프로젝트 절대경로 제거하고 상대경로로 변경(Assets는 남기기)
string atrAssetPath = strFullFilePath.Replace(Application.dataPath, "Assets");
Debug.LogWarningFormat("[atrAssetPath] {0}", atrAssetPath);
TrueTypeFontImporter cImporter = AssetImporter.GetAtPath(atrAssetPath) as TrueTypeFontImporter;
if (null != cImporter)
{
cImporter.includeFontData = _bActive;
cImporter.SaveAndReimport();
Debug.LogWarningFormat("[atrAssetPath] {0} [cImporter.includeFontData] {1}", atrAssetPath, cImporter.includeFontData);
}
}
}
foreach (System.IO.DirectoryInfo sdi in di.GetDirectories())
{
Debug.LogWarningFormat("[SubDirectory.FullName] {0}", sdi.FullName);
ProcessIncludeFontData(sdi.FullName, _bActive);
}
}
/// <summary>
/// IncludeFontData 활성화
/// </summary>
public static void ActiveTrueTypeFont_IncludeFontData()
{
if (false == Directory.Exists(m_strDynamicFontFolderPath))
return;
ProcessIncludeFontData(m_strDynamicFontFolderPath, true);
}
/// <summary>
/// IncludeFontData 비활성화
/// </summary>
public static void InActiveTrueTypeFont_IncludeFontData()
{
if (false == Directory.Exists(m_strDynamicFontFolderPath))
return;
ProcessIncludeFontData(m_strDynamicFontFolderPath, false);
}
P.s. NGUI Font는 해당 옵션이 없어서 어떻게 처리해야될지 고민..
'Unity3D > Font' 카테고리의 다른 글
[링크] [Unity] AssetBundle & Addressable 폰트 중복 로드 문제 (0) | 2025.02.17 |
---|---|
[폰트병합] 여러가지 폰트 합치기(with FontCreator 15.0) (0) | 2025.02.11 |
[펌] [정보] 글자가 부족한 폰트를 다른 폰트와 합치는 법(with FontForge) (0) | 2025.02.06 |
[링크] 폰트 합치기(with FontCreator 6.0) (0) | 2025.02.06 |
[링크][폰트] 서브셋 경량화, WOFF 변환+상용 한글, 제1수준 한자, 특수기호 (0) | 2024.06.24 |