Version: 5.5
콘텐츠 보호
에셋 번들의 디스크 검색 최적화(Optimizing disk seeks with AssetBundles)

에셋 번들에 스크립트 포함

에셋 번들은 스크립트를 TextAssets으로 포함할 수는 있지만 이렇게 포함된 스크립트는 실제로 실행 가능한 코드가 아닙니다. 에셋 번들에 코드를 포함시키고 이를 애플리케이션에서 실행시키려면, 어셈블리에서 미리 컴파일한 후 Mono Reflection 클래스를 사용하여 로드해야 합니다. iOS와 같이 AOT 컴파일을 사용하는 플랫폼에서는 리플랙션을 사용할 수 없습니다. 어셈블리는 Monodevelop, Visual Studio 등과 같은 일반적인 C# IDE나 Mono 또는 .NET 컴파일러를 사용하는 모든 텍스트 에디터에서 생성할 수 있습니다.

참고: Windows 스토어 앱과 Windows 휴대폰은 에셋 번들에서 스크립트 로딩을 지원하지 않습니다.

//c# example
string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";
IEnumerator Start () {
    while (!Caching.ready)
        yield return null;

    // Start a download of the given URL
    WWW www = WWW.LoadFromCacheOrDownload (url, 1);

    // Wait for download to complete
    yield return www;

    // Load and retrieve the AssetBundle
    AssetBundle bundle = www.assetBundle;

    // Load the TextAsset object
    TextAsset txt = bundle.Load("myBinaryAsText", typeof(TextAsset)) as TextAsset;

    // Load the assembly and get a type (class) from it
    var assembly = System.Reflection.Assembly.Load(txt.bytes);
    var type = assembly.GetType("MyClassDerivedFromMonoBehaviour");

    // Instantiate a GameObject and add a component with the loaded class
    GameObject go = new GameObject();
    go.AddComponent(type);
}

콘텐츠 보호
에셋 번들의 디스크 검색 최적화(Optimizing disk seeks with AssetBundles)