본문 바로가기

develop

[Unity] AssetBundle 빌드하기

- AssetBundle을 생성하기 위한 코드. C#

http://docs.unity3d.com/Documentation/ScriptReference/BuildPipeline.BuildAssetBundle.html

주의 : 이 코드를 포함하고 있는 스크립트는 유니티 엔진 프로젝트에 Editor 폴더를 만들고 그 하위에 두어야 한다. Editor 폴더의 위치는 상관 없다.

// 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 );
        }
    }
}

- AssetBundle로 만들려는 리소스를 클릭한 상태에서 "Assets>Build AssetBundle From Selection - Track dependencies"를 누른다.

- AssetBundle을 저장할 위치를 선택하고 저장하면 AssetBundle이 생성된다.

- AssetBundle은 에디터로 만들고 어플리케이션 내에서 동적으로 로드해서 사용한다.

- AssetBundle은 일종의 압축파일이다.

 

반응형