Unity

210726_유니티 Asset Bundle

minquu 2021. 7. 26. 13:49
반응형

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

 

유니티 - 매뉴얼: 에셋번들 (AssetBundles)

로우 레벨 네이티브 플러그인 인터페이스(Low-level Native Plugin Interface) 4.x버전에서의 에셋번들 빌드 에셋번들 (AssetBundles) 에셋 번들은 Unity에서 원하는 에셋을 포함하여 익스포트할 수 있는 파일입

docs.unity3d.com

 

 

https://docs.unity3d.com/kr/530/ScriptReference/AssetBundle.html

 

Unity - 스크립팅 API: AssetBundle

번들은 플랫폼간에 완벽히 호환되지 않는 점에 유의하십시오. Standalone플랫폼은(WebPlayer를 포함하여)에서 빌드된 번들은 어떤 플랫폼에서든 로드 될수 있지만, iOS 나 Android에서는 사용할 수 없습

docs.unity3d.com

 

https://learn.unity.com/tutorial/introduction-to-asset-bundles

 

Introduction to Asset Bundles - Unity Learn

An AssetBundle is content that is stored separately from a main game or application and loaded (or downloaded, in the case of mobile and online apps) at runtime. This helps minimize the impact on network and system resources by allowing customers to downlo

learn.unity.com

 

 

 

 

참고 사이트 

 

----

 

에셋 번들

에셋번들은 에셋(모델, 텍스처, 프리팹, 오디오 클립, 씬 등)의 묶음을 의미한다

에셋번들을 이용하면 프로그램 실행중에 동적으로 에셋을 로드할 수 있다

에셋번들은 게임 등에서 콘텐츠를 다운로드 할 경우 유용하게 사용될 수 있다

 

게임 할 때 추가 리소스를 다운 받는 것들이 에셋 번들임

 

 

유니티 새로운 프로젝트를 만들어서 

 

sd 시티즌을 임포트 해준다.

 

 

 

캐릭터 프리팹 끌어다가 두고, 언팩해주기

 

 

 

리소스 - 프리팹 폴더 만들어서 넣어주고

하이라키지워준다.

 

회사에서는 로컬, 서버 환경 두 가지로 테스트를 많이한다.

 

 

 

웨폰도 똑같이 해준다.

 

그래서 캐릭터 에셋 번들, 웨폰 에셋 번들 이 두 가지를 만들 것이다.

 

 

 

 

 

 

new 눌러서 Characters 라고 적어준다.

 

 

 

무기도 똑같이 만들어준다.

 

 

새로운 스크립터 만들어주고

 

 

에셋번들(AssetBundle) 빌드

스크립트

에셋 번들 브라우저(Asset Bundle Browser)

(코드를 사용하지 않고 간단하게 에셋번들을 만들 수 있습니다.)

https://docs.unity3d.com/Manual/AssetBundles-Browser.html

 

Unity - Manual: Unity Asset Bundle Browser tool

AssetBundle Download Integrity and Security Unity Asset Bundle Browser tool You can use the Asset Bundle Browser to view and edit the configuration of asset bundles in your Unity project. For more information, see the Unity Asset Bundle Browser documentati

docs.unity3d.com

 

--- 이런 것도 있다

 

하지만 우리는 코드를 친다.

 

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;


public class CreateAssetBundles 
{
    [MenuItem("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles()
    {
        Debug.Log("Assets/Build AssetBundles");
    }
}

 

 

유니티 에디터 

 

위에 메뉴에 창이 생기고, 누르면 로그 뜨게한다.

 

 

using UnityEngine;
using UnityEditor;
using System.IO;

public class CreateAssetBundles
{
    [MenuItem("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles()
    {
        string path = "Assets/AssetBundles";
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.None, BuildTarget.Android);
    }
}

 

 

스크립터는 꼭 에디터 폴더 들어가있어야함

 

 

 

 

생김

 

 

 

manifest 열어보면

어떤게 들어가있는지확인할 수 있다.

 

얘는 전체 어셋번들의 정보가 들어 가 있음

 

이런식으로

 

FTP나 드라이브에 올릴때는 

 

.meta 형식을 제외한 것을 올리면 된다.

 

----

 

먼저 로컬부터 테스트 해본다.

 

 

 

 

 

 

스크립터들 만들기

 

 

 

스크립터 작성

 

AssetManager  - 싱글턴으로 사용

 

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

public class AssetManager : MonoBehaviour
{

    public static AssetManager instance;

    private void Awake()
    {
        AssetManager.instance = this;


    }
    public IEnumerator LoadFromMemoryAsynce(string path, System.Action<AssetBundle> callback) {
        //파일을 바이트 배열로 읽어서 비동기 방식로 로드한다.

        byte[] binary = File.ReadAllBytes(path);
        AssetBundleCreateRequest req = 
        AssetBundle.LoadFromMemoryAsync(binary);

        yield return req;

        callback(req.assetBundle);

    }

}

 

APP 에서 코루틴으로 소환

 

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

public class App : MonoBehaviour
{

    //List<AssetBundle> bundle = new List<AssetBundle>();
    //Dictionary<string, AssetBundle> dicBundles = new Dictionary<string, AssetBundle>();

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(
                    AssetManager.instance.LoadFromMemoryAsynce("Assets/AssetBundles/characters", (bundle) =>
                    {
                        Debug.LogFormat("bundle: {0}", bundle);
                        var prefab = bundle.LoadAsset<GameObject>("ch_01_01");
                        var model = Instantiate<GameObject>(prefab);
                    })
            );
    }
}

 

 

 

생성이 된다.

 

 

-----

 

https://github.com/Unity-Technologies/AssetBundles-Browser

 

 

GitHub - Unity-Technologies/AssetBundles-Browser: Editor tool for viewing and debugging asset bundle contents before and after b

Editor tool for viewing and debugging asset bundle contents before and after builds - GitHub - Unity-Technologies/AssetBundles-Browser: Editor tool for viewing and debugging asset bundle contents b...

github.com

 

 

다운 받아서

 

 

 

 

 

 

생성됨

 

 

------

 

서버에서 생성

 

--

학원 게시물 확인하기

 

 

반응형

'Unity' 카테고리의 다른 글

Unity Addressables Remote로 서버에서 다운로드 받기  (0) 2022.06.15
Unity Addressables 정리  (0) 2022.06.14