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파일은 모두 처리하도록 해뒀다.
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 strFullFilePath = fi.FullName.Replace("\\" , "/" );
Debug.LogWarningFormat("[strFullFilePath] {0}" , strFullFilePath);
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);
}
}
public static void ActiveTrueTypeFont_IncludeFontData ( )
{
if (false == Directory.Exists(m_strDynamicFontFolderPath))
return ;
ProcessIncludeFontData(m_strDynamicFontFolderPath, true );
}
public static void InActiveTrueTypeFont_IncludeFontData ( )
{
if (false == Directory.Exists(m_strDynamicFontFolderPath))
return ;
ProcessIncludeFontData(m_strDynamicFontFolderPath, false );
}
P.s. NGUI Font는 해당 옵션이 없어서 어떻게 처리해야될지 고민..