블로그 이미지
Every unexpected event is a path to learning for you. blueasa

카테고리

분류 전체보기 (2809)
Unity3D (865)
Programming (479)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (234)
협업 (61)
3DS Max (3)
Game (12)
Utility (140)
Etc (98)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (55)
Android (16)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday

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는 해당 옵션이 없어서 어떻게 처리해야될지 고민..

반응형
Posted by blueasa
, |