Unity3D AssetBundle 생성부터 패치 및 적용까지. 1 - Build AssetBundle

 유니티3D 에셋 번들 작업 관련 링크를 정리했었습니다. 이번 포스팅은 유니티3D 공식 문서에도 있는 에셋 번들 빌드하는 것을 정리해보겠습니다. 기타 에셋 번들에 대한 개념들은 앞서 정리한 포스팅에 있는 관련 링크를 참고하세요.

  본격적으로 정리하기에 앞서 에셋스토어에 에셋 번들 관련된 것이 하나 있어서 소개합니다. Asset Bundle Creator라는 플러그인입니다. 폴더 단위로 에셋 번들을 쉽게 만들어 주는 듯 합니다. 직접 구현하지 않을실 분들은 가격도 10$뿐이 안하니 하나 지르시는것도 좋겠죠.



    // C# Example
    // Builds an asset bundle from the selected objects in the project view.
    // Once compiled go to "Menu" -> "Assets" and select one of the choices
    // to build the Asset Bundle
    
    using UnityEngine;
    using UnityEditor;
    public class ExportAssetBundles {
        [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
        static void ExportResource () {
            // Bring up save panel
            string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
            if (path.Length != 0) {
                // Build the resource file from the active selection.
                Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
                BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
                Selection.objects = selection;
            }
        }
        [MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
        static void ExportResourceNoTrack () {
            // Bring up save panel
            string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
            if (path.Length != 0) {
                // Build the resource file from the active selection.
                BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
            }
        }
    }

 C# 파일명을 ExportAssetBundles로 하나 만들어줍니다. 그리고 유니티3D 공식 문서의 소스를 위와같이 그대로 가져옵니다. 혹시 복사&붙여넣기 하지 않고 일일이 타이핑을 하신분들은 처음 파일을 만들면 public class ExportAssetBundles : MonoBehaviour { 일텐데 굳이 MonoBehaviour을 상속받지 않아도 작동하므로 긁어온데로 사용합니다. Start()와 Update()도 지우시구요.

 이제 유니티 에디터의 Project뷰에서 에셋 번들로 만들 에셋을 선택하고 Assets -> Build AssetBundle From Selection - Track dependencies를 선택합니다. 저는 NANUMPEN 폰트를 선택하고 진행했습니다.

 파일 저장 다이얼로그가 뜹니다. 디폴트 이름으로 New Resource로 정했으니 이걸로 일단 저장합니다.

 New Resource.unity3d 에셋 번들이 생성되었습니다. 원본이 3메가 넘는데 반해 에셋 번들은 1메가도 안되는거 보면 자체 압축 메커니즘이 있나보네요.

 다음에는 코루틴을 사용해서 에셋 번들 패치하는 프로세스를 간략히 정리해보겠습니다.

댓글

이 블로그의 인기 게시물

'xxx.exe' 프로그램을 시작할 수 없습니다. 지정된 파일을 찾을 수 없습니다.

goorm IDE에서 node.js 프로젝트로 Hello World Simple Server 만들어 띄워보기

애드센스 수익을 웨스턴 유니온으로 수표대신 현금으로 지급 받아보자.