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

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
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
04-28 00:03

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

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

빌드 전(PreProcessor)에 잠시 다른 곳(Temp)으로 옮겼다가, 빌드 후(PostProcessor)에 되돌려 놓도록 함.

 

using System;
using UnityEditor;
using UnityEditor.Build;
#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을 옮겨뒀다가, 빌드 후(Postprocessor) 되돌려 놓음
    /// </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_strTemp = "Temp";
        private static readonly string m_strAssetBundlesPath_Builtin_Android = "Assets/StreamingAssets/AssetBundles/Android";
        private static readonly string m_strAssetBundlesPath_Builtin_iOS = "Assets/StreamingAssets/AssetBundles/iOS";
        private static readonly string m_strAssetBundlesPath_Temp_Android = "Assets/Temp/Android";
        private static readonly string m_strAssetBundlesPath_Temp_iOS = "Assets/Temp/iOS";

        public int callbackOrder { get { return 0; } }

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

            // Temp 폴더 없으면 생성
            if (false == AssetDatabase.IsValidFolder("Assets/Temp"))
            {
                Debug.LogWarning("[OnPreprocessBuild] Create 'Temp' Folder");
                AssetDatabase.CreateFolder("Assets", m_strTemp);
                AssetDatabase.Refresh();
            }

            // 빌드 전, 다른 플랫폼 AssetBundle 폴더 임시 Move(제외)
#if UNITY_ANDROID
            if (true == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Builtin_iOS)
                && false == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Temp_iOS))
            {
                Debug.LogWarning("[OnPreprocessBuild] Move 'iOS' Folder to 'Temp'");
                AssetDatabase.MoveAsset(m_strAssetBundlesPath_Builtin_iOS, m_strAssetBundlesPath_Temp_iOS);
                AssetDatabase.Refresh();
            }
#elif UNITY_IOS
            if (true == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Builtin_Android)
                && false == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Temp_Android))
            {
                Debug.LogWarning("[OnPreprocessBuild] Move 'Android' Folder to 'Temp'");
                AssetDatabase.MoveAsset(m_strAssetBundlesPath_Builtin_Android, m_strAssetBundlesPath_Temp_Android);
                AssetDatabase.Refresh();
            }
#endif
        }

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

            // 빌드 후, Move(제외) 됐던 다른 플랫폼 AssetBundle 폴더 원래 자리로 되돌리기
#if UNITY_ANDROID
            if (true == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Temp_iOS)
                && false == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Builtin_iOS))
            {
                Debug.LogWarning("[OnPreprocessBuild] Return 'iOS' Folder From 'Temp'");
                AssetDatabase.MoveAsset(m_strAssetBundlesPath_Temp_iOS, m_strAssetBundlesPath_Builtin_iOS);
                AssetDatabase.Refresh();
            }
#elif UNITY_IOS
            if (true == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Temp_Android)
                && false == AssetDatabase.IsValidFolder(m_strAssetBundlesPath_Builtin_Android))
            {
                Debug.LogWarning("[OnPreprocessBuild] Return 'Android' Folder From 'Temp'");
                AssetDatabase.MoveAsset(m_strAssetBundlesPath_Temp_Android, m_strAssetBundlesPath_Builtin_Android);
                AssetDatabase.Refresh();
            }
#endif
        }
    }
}

 

 

반응형
Posted by blueasa
, |