Unity/Else

Unity Asset Bundle

🟦 Unity Asset Bundle

🟧 Document

https://docs.unity3d.com/kr/530/Manual/BuildingAssetBundles.html

 

μœ λ‹ˆν‹° - 맀뉴얼: 4.xλ²„μ „μ—μ„œμ˜ μ—μ…‹λ²ˆλ“€ λΉŒλ“œ

μ—μ…‹λ²ˆλ“€ (AssetBundles) 4.xλ²„μ „μ—μ„œμ˜ μ—μ…‹λ²ˆλ“€ λΉŒλ“œ To begin creating an AssetBundle (called AssetBundle in scripts and within the Unity Editor), select an asset from your project folder that you want to include in a bundle. At the very bott

docs.unity3d.com

https://docs.unity3d.com/2017.4/Documentation/Manual/AssetBundles-Native.html

 

Unity - Manual: Using AssetBundles Natively

Using AssetBundles Natively Important note: The AssetBundle Manager is deprecated for Unity versions 2018.2 and higher. It is no longer available from the Asset Store, but you can still download it from the AssetBundleDemo Bitbucket repository. If you use

docs.unity3d.com

 

 

 

🟦 Bundle Build

- AssetBundle을 μ •μ˜ : bundle_1

 

 

 

- Box ν”„λ¦¬νŒΉλ„ bundle_1둜 μ„€μ •

 

 

 

- 폴더 생성 : AssetBundles

 

 

 

- 폴더 생성 : Editor

    - 슀크립트 생성 : CreateAssetBundles

 

 

 

using UnityEditor;

public class CreateAssetBundles
{
    [MenuItem("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles()
    {
        // μ—μ…‹λ²ˆλ“€ 생성 경둜, λΉŒλ“œ μ˜΅μ…˜, λΉŒλ“œ λŒ€μƒ ν”Œλž«νΌ
        BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.Android);
    }
}

 

 

 

- Build AssetBundles ν΄λ¦­ν•˜λ©΄ μ—μ…‹λ²ˆλ“€μ„ λΉŒλ“œν•¨

 

 

 

- AssetBundles 폴더 μ•ˆμ— μœ„μ™€ 같은 파일이 μƒμ„±λœ 것을 확인

 

 

 

🟦 Bundle Load

🟧 LoadFromMemoryAsync

- 빈 κ²Œμž„μ˜€λΈŒμ νŠΈ 생성 : LoadManager

- 슀크립트 생성 : LoadManager

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class LoadManager : MonoBehaviour
{
    // λ‘œλ“œν•  μ—μ…‹λ²ˆλ“€ 경둜
    private string assetBundlePath = "Assets/AssetBundles/bundle_1";
    // 뢈러올 였브젝트 이름
    private string asset_box = "Box";

    void Start()
    {
        StartCoroutine(nameof(LoadFromMemoryAsync), assetBundlePath);
    }

    IEnumerator LoadFromMemoryAsync(string path)
    {
        // 지정 κ²½λ‘œμ— μžˆλŠ” λͺ¨λ“  λ°”μ΄νŠΈλ₯Ό μ½μ–΄μ„œ λ‘œλ“œ
        AssetBundleCreateRequest createRequest = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path));
        // λͺ¨λ‘ λ‘œλ“œν•  λ•ŒκΉŒμ§€ λŒ€κΈ°
        yield return createRequest;

        AssetBundle bundle = createRequest.assetBundle;
        // λ‘œλ“œν•œ μ—μ…‹λ²ˆλ“€μ—μ„œ κ²Œμž„μ˜€λΈŒμ νŠΈ λ‘œλ“œ
        var prefab = bundle.LoadAsset<GameObject>(asset_box);

        // 뢈러온 κ²Œμž„μ˜€λΈŒμ νŠΈ 생성
        Instantiate(prefab);
    }
}

 

 

 

- μ—μ…‹λ²ˆλ“€λ‘œ μ„€μ •ν•œ Box ν”„λ¦¬νŒΉμ„ μ‚­μ œ ν›„ Play

'Unity > Else' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

λ ˆμ΄μ•„μ›ƒ μž¬μ •λ ¬  (0) 2022.05.27
Unity VScode Debugging  (0) 2022.05.23
Animation Rigging  (0) 2022.04.01
AudioMixer  (0) 2021.10.31
TMP(Text Mesh Pro) ν•œκΈ€ 생성  (0) 2021.10.30