블로그 이미지
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
, |

[링크] https://codingstarter.tistory.com/37

 

[Unity] AssetBundle & Addressable 폰트 중복 로드 문제

- UI를 번들에서 로드하도록 수정 했더니 메모리에 동일한 폰트가 중복으로 로드되는 현상이 발생 - 동일한 폰트여도 각 번들마다 개별적으로 로드되는 것으로 추정 - 폰트 에셋의 Include Font Data

codingstarter.tistory.com

 

 

 

반응형
Posted by blueasa
, |

[수정] Rename 방식으로 변경(2024-07-04]

----

 

[빌드 시, Builtin AssetBundles에서 해당 Platform 에셋번들만 빌드 되도록 하기 위한 PreProcessor 추가]

기본적으로 에셋번들은 플랫폼 별로 모두 가지고 있는데 해당 플랫폼에 맞는 에셋번들만 빌드 되도록 하기 위해서

빌드 전(Preprocessor) 해당 안되는 AssetBundle을 Hidden 폴더(예:.Android or .iOS)로 Rename 했다가, 빌드 후(Postprocessor) 되돌려 놓음.

 

using System;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build;
using System.IO;
#if UNITY_2018_1_OR_NEWER
using UnityEditor.Build.Reporting;
#endif
using UnityEditor.Callbacks;

namespace blueasa
{
    /// <summary>
    /// 빌드 시, Built-in AssetBundle에서 해당 Platform AssetBundle만 빌드 되도록 하기 위한 Preprocessor
    /// 빌드 전(Preprocessor) 해당 안되는 AssetBundle을 Hidden 폴더(예:.Android or .iOS)로 Rename 했다가, 빌드 후(Postprocessor) 되돌려 놓음
    /// [Hidden(./~) 참조] https://docs.unity3d.com/kr/2021.3/Manual/SpecialFolders.html
    /// </summary>
#if UNITY_2018_1_OR_NEWER
    public class BuildPreprocessor_BuiltinAssetBundle : IPreprocessBuildWithReport, IPostprocessBuildWithReport
#else
    public class BuildPreprocessor_BuiltinAssetBundle : IPreprocessBuild, IPostprocessBuild
#endif
    {
        private static readonly string m_strAndroid = "Android";
        private static readonly string m_strDotAndroid = ".Android";
        private static readonly string m_striOS = "iOS";
        private static readonly string m_strDotiOS = ".iOS";
        private static readonly string m_strDotMeta = ".meta";
        private static readonly string m_strAssetBundles = "AssetBundles";

        private static readonly string m_strDataPath = Application.dataPath;
        private static readonly string m_strStreamingAssetsPath = Application.streamingAssetsPath;
        
        private static readonly string m_strAssetBundlesPath_Builtin_FullPath = string.Format("{0}/{1}", m_strStreamingAssetsPath, m_strAssetBundles);
        private static readonly string m_strAssetBundlesPath_Builtin_Android_FullPath = string.Format("{0}/{1}", m_strAssetBundlesPath_Builtin_FullPath, m_strAndroid);
        private static readonly string m_strAssetBundlesPath_Builtin_DotAndroid_FullPath = string.Format("{0}/{1}", m_strAssetBundlesPath_Builtin_FullPath, m_strDotAndroid);
        private static readonly string m_strAssetBundlesPath_Builtin_iOS_FullPath = string.Format("{0}/{1}", m_strAssetBundlesPath_Builtin_FullPath, m_striOS);
        private static readonly string m_strAssetBundlesPath_Builtin_DotiOS_FullPath = string.Format("{0}/{1}", m_strAssetBundlesPath_Builtin_FullPath, m_strDotiOS);

        public int callbackOrder { get { return 0; } }

        private static void Refresh()
        {
            System.Threading.Thread.Sleep(100);
            AssetDatabase.Refresh();
            System.Threading.Thread.Sleep(100);
        }

#if UNITY_2018_1_OR_NEWER
        public void OnPreprocessBuild(BuildReport report)
#else
        public void OnPreprocessBuild(BuildTarget target, string path)
#endif
        {
            Debug.LogWarning($"[OnPreprocessBuild] {this}");

            // 빌드 전, 다른 플랫폼 AssetBundle 폴더 임시 제외
#if UNITY_ANDROID
            // [Rename]
            if (true == Directory.Exists(m_strAssetBundlesPath_Builtin_iOS_FullPath)
                && false == Directory.Exists(m_strAssetBundlesPath_Builtin_DotiOS_FullPath))
            {
                Debug.LogWarning("[OnPreprocessBuild] Rename 'iOS' Folder to '.iOS'");
                Directory.Move(m_strAssetBundlesPath_Builtin_iOS_FullPath, m_strAssetBundlesPath_Builtin_DotiOS_FullPath);
                // 빈(Empty) 폴더 생성을 방지하기 위해서 폴더의 meta 파일도 함께 삭제
                if (true == File.Exists(m_strAssetBundlesPath_Builtin_iOS_FullPath + m_strDotMeta))
                {
                    File.Delete(m_strAssetBundlesPath_Builtin_iOS_FullPath + m_strDotMeta);
                }
                Refresh();
            }
#elif UNITY_IOS
            // [Rename]
            if (true == Directory.Exists(m_strAssetBundlesPath_Builtin_Android_FullPath)
                && false == Directory.Exists(m_strAssetBundlesPath_Builtin_DotAndroid_FullPath))
            {
                Debug.LogWarning("[OnPreprocessBuild] Rename 'Android' Folder to '.Android'");
                Directory.Move(m_strAssetBundlesPath_Builtin_Android_FullPath, m_strAssetBundlesPath_Builtin_DotAndroid_FullPath);
                // 빈(Empty) 폴더 생성을 방지하기 위해서 폴더의 meta 파일도 함께 삭제
                if (true == File.Exists(m_strAssetBundlesPath_Builtin_Android_FullPath + m_strDotMeta))
                {
                    File.Delete(m_strAssetBundlesPath_Builtin_Android_FullPath + m_strDotMeta);
                }
                Refresh();
            }
#endif
            // Start listening for errors when build starts
            Application.logMessageReceived += OnBuildError;
        }

        // CALLED DURING BUILD TO CHECK FOR ERRORS
        private void OnBuildError(string condition, string stacktrace, LogType type)
        {
            Debug.LogWarning($"[OnBuildError] {condition} {stacktrace} {type}");

            if (type == LogType.Error)
            {
                // FAILED TO BUILD, STOP LISTENING FOR ERRORS
                Application.logMessageReceived -= OnBuildError;

                // 빌드 에러 시에도 이동된 파일 되돌리기
                RestoreTemporarilyMovedAssetbundles();
            }
        }

#if UNITY_2018_1_OR_NEWER
        public void OnPostprocessBuild(BuildReport report)
#else
        public void OnPostprocessBuild(BuildTarget target, string path)
#endif
        {
            Debug.LogWarning($"[OnPostprocessBuild] {this}");

            // [빌드 후] 제외 됐던 다른 플랫폼 AssetBundle 폴더 되돌리기
            RestoreTemporarilyMovedAssetbundles();

            // IF BUILD FINISHED AND SUCCEEDED, STOP LOOKING FOR ERRORS
            Application.logMessageReceived -= OnBuildError;
        }

        public static void RestoreTemporarilyMovedAssetbundles()
        {
            Debug.LogWarning($"[RestoreTemporarilyMovedAssetbundles]");

            // [빌드 후] 제외 됐던 다른 플랫폼 AssetBundle 폴더 되돌리기
#if UNITY_ANDROID
            // [Rename]
            if (true == Directory.Exists(m_strAssetBundlesPath_Builtin_DotiOS_FullPath)
                && false == Directory.Exists(m_strAssetBundlesPath_Builtin_iOS_FullPath))
            {
                Debug.LogWarning("[OnPreprocessBuild] Rename '.iOS' Folder to 'iOS'");
                Directory.Move(m_strAssetBundlesPath_Builtin_DotiOS_FullPath, m_strAssetBundlesPath_Builtin_iOS_FullPath);
                Refresh();
            }
#elif UNITY_IOS
            // [Rename]
            if (true == Directory.Exists(m_strAssetBundlesPath_Builtin_DotAndroid_FullPath)
                && false == Directory.Exists(m_strAssetBundlesPath_Builtin_Android_FullPath))
            {
                Debug.LogWarning("[OnPreprocessBuild] Rename '.Android' Folder to 'Android'");
                Directory.Move(m_strAssetBundlesPath_Builtin_DotAndroid_FullPath, m_strAssetBundlesPath_Builtin_Android_FullPath);
                Refresh();
            }
#endif
        }
    }
}

 

 

반응형
Posted by blueasa
, |

[TroubleShooting]


[에러메시지]

NotSupportedException: .... System.Net.WebRequest.GetCreator (System.String prefix) System.Net.WebRequest.Create (System.Uri requestUri)


PC/iOS에서는 잘 되는데 Android에서 위와 같은 NotSupportedException이 난다.(현재 Unity v5.6.5f1)

검색해보니 게임코디에 아래와 같은 답변을 해주신 분이 있다.



  비회원: 
kimsama

NotSupportedException: .... System.Net.WebRequest.GetCreator (System.String prefix) System.Net.WebRequest.Create (System.Uri requestUri) 모바일에서 위의 에러로 인해 HttpWebReaquest 를 사용하지 못하는 경우라면 여기 링크의 내용 참고하시기 바랍니다. http://www.vovchik.org/blog/13001 간단하게 우회하는 방법이 나와 있습니다.

[출처] http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_QnA_etc&page=2&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=2617



그래서 링크(http://www.vovchik.org/blog/13001)에서 말해준 대로 Wrapping을 해서 Android에서 돌려보니 잘된다!!

(kimsama님 감사합니다!)


내가 추가 및 수정한 소스는 아래와 같다.


// Wrapper Class
using System;
using System.Net;

public class HttpRequestCreator : IWebRequestCreate 
{
	public WebRequest Create(Uri uri)
	{
		return new HttpWebRequest(uri);	
	}
}


    //Get size of the asset
    HttpRequestCreator cHttpRequestCreator = new HttpRequestCreator();            // modify
    System.Net.WebRequest req = cHttpRequestCreator.Create(new Uri(assetURL));    // modify
    req.Method = "HEAD";

    float ContentLength;
    using (System.Net.WebResponse resp = req.GetResponse())
    {
        float.TryParse(resp.ContentLength.ToString(), out ContentLength);
    }

    while (!download.isDone)
    {
        if (progressBar != null)
	    {
            progressBar.LabelInformations = "Downloading Assets";
            progressBar.Progress = download.progress;
            progressBar.AssetSize = ContentLength / 1000000; //(Mb)
	    }
	    yield return null;
    }






- CDN에 있는 파일 사이즈를 어떻게 알 수 없나 하고 찾다가 테스트 해보고 잘 되길래 올려 놓음.

  (PC/iOS는 잘되는데 Android가 에러나서 위와 같이 고침)

    1. //Get size of the asset
    2. System.Net.WebRequest req = System.Net.HttpWebRequest.Create(assetURL);
    3. req.Method = "HEAD";
    4. float ContentLength;
    5. using (System.Net.WebResponse resp = req.GetResponse())
    6. {
    7. float.TryParse(resp.ContentLength.ToString(), out ContentLength);
    8. }
    9. while (!download.isDone)
    10. {
    11. if (progressBar != null)
    12. {
    13. progressBar.LabelInformations = "Downloading Assets";
    14. progressBar.Progress = download.progress;
    15. progressBar.AssetSize = ContentLength / 1000000; //(Mb)
    16. }
    17. yield return null;
    18. }


[출처] https://answers.unity.com/questions/1035361/get-size-of-an-online-assetbundle-and-progress-in.html




반응형
Posted by blueasa
, |
반응형
Posted by blueasa
, |
반응형
Posted by blueasa
, |



[링크] https://bitbucket.org/Unity-Technologies/assetbundledemo


[링크] https://assetstore.unity.com/packages/tools/utilities/assetbundle-manager-example-scenes-45836

반응형
Posted by blueasa
, |

5.2 이후 바뀐 에셋번들을 처음 접해봤는데 이전보다는 심플해져서 사용하긴 쉬운 것 같다.


근데 서버에서 외부(앱 내 저장 가능한 공간 : Application.persistentDataPath 사용)에 다운로드를 받고 로드 할 때 삽질한 내용을 간단하게 올려 놓는다.


지금은 바빠서..


간단하게 올리고 나중에 퇴고를 해야겠다..



[삽질_1]

- PC에서는 잘되는데 Android에서 Application.persistentDataPath로만 접근 하는데,

  Write 할 때 Path가 mnt로 시작하는 외부 저장소 Path로 저장 됨.

  AssetBundle을 로드 하기 위해 Read 하려고 접근하니 Stroage로 시작하는 내부 저장소 Path를 줌.

[처리_1]

- 우선 강제로 내부 저장소만 사용하도록 프로젝트 셋팅에서 변경

   (Project Settings-Android-Configuration-Write Permission 을 Internal로 변경)



[삽질_2]

- 빈번하게 에셋번들 로컬 로드 시, 무한루프에 빠짐

[처리_2]

- 처리하기 편하려고 BundleName과 AssetName을 같게 했는데 유니티가 헷갈려하면서 뭔가 문제가 생기는 것 같아서

  BundleName 셋팅에 확장자를 추가(인스펙터에서 셋팅)하니 잘 됨.



[삽질_3]

- 제대로 다하고 올린 것 같은데 이전에 잘 로드 되던 파일이 에러가 나서 당황함.


[처리_3]

- 파일질라로 에셋번들 파일을 업로드 할 때 Binary로 올리지 않으면 문제가 생긴다고 함.

  파일질라 셋팅을 수정하고 다시 업로드 해서 해결

  (전송-전송 유형-바이너리 로 변경)

- [참조] http://blueasa.tistory.com/2110

  


반응형
Posted by blueasa
, |


[링크] http://unitylist.com/r/6js/unity-5-assert-bundle

반응형
Posted by blueasa
, |


[링크] https://github.com/kimsama/Unity5-AssetBundleSetting

반응형

'Unity3D > AssetBundle' 카테고리의 다른 글

[펌] 에셋번들 생성하기 & 다운로드  (0) 2017.04.12
[링크] 에셋번들 로딩 방식 4가지  (0) 2017.03.03
WWW.LoadFromCacheOrDownload  (0) 2015.04.23
AssetBundle 가이드  (0) 2015.01.26
AssetBundle 버전체크 방식..  (0) 2014.04.21
Posted by blueasa
, |