[Build] 빌드 시, Builtin 되는 AssetBundle 중 현재 Platform의 AssetBundle만 빌트인 되도록 하기
[빌드 시, 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
}
}
}
'Unity3D > Script' 카테고리의 다른 글
[ChatGPT] Multi-Key Dictionary in Unity? (0) | 2023.08.07 |
---|---|
[링크] 유니티 - Scripting Define Symbol 스크립트로 제어하기 (0) | 2022.07.20 |
[펌] 유니티 MonoBehaviour 상속 안 받고 코루틴 사용하기 (0) | 2022.05.18 |
[링크] Well512 알고리즘 예제, 난수 생성기, 랜덤 포레스트(Random Forest) (0) | 2021.10.25 |
[펌] WELL 512 랜덤 알고리즘 (0) | 2021.09.02 |