반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

가끔 보자, 하늘.

unity5에서의 신규 AssetBundle 빌드 시스템 본문

개발 이야기/개발 및 서비스

unity5에서의 신규 AssetBundle 빌드 시스템

가온아 2015. 3. 19. 19:07

참고용으로 퇴고는 하지 않았습니다. 아직 unity 초보라 잘 모르는 내용들이 포함되어 있기에, 다른 튜토리얼 보면서 차근 차근 할 예정입니다.


(* 원본 : http://forum.unity3d.com/threads/new-assetbundle-build-system-in-unity-5-0.293975/)


Unity 5.0에서의 새로운 AssetBundle


Basic Introduction


신규 AssetBundle build 시스템에서는 아래와 같은 것들이 제공된다.


1. AssetBundle에서 assets을 mark 할 수 있는 간편한 UI, 그리고 asset database에 AssetBundle을 매핑하는 것을 그 assets에 유지한다.

 : asset preview panel의 하단에서 UI를 찾을 수 있으며, 사용법은 간단한다.

 : AssetBundle 이름은 meta file에 저장된다.

 : 또한 검색 바에서 검색필터를 제공한다. AssetBundle에 기록했던 이름을 검색할 때 "b:"를 같이 입력하면 찾을 수 있다.

  : 몇가지 제한 사항이 있다.

    > 여러 AssetBundle에 하나의 asset mark를 허용하지 말 것!

> AssetBundle 이름으로만 relative path(?)를 설정할 수 있음.

> AssetBundle 에 scripts를 mark 할 수 없음

> scene aset을 mark할 수 없으며 같은 AssetBundle안에 normal asset(?)을 mark 할 수 없음


2. AssetBundle에 asset을 mark 하는 API

 : AssetBundle 이름을 설정할 때 AssetImporter.assetBundleName 을 사용한다.

 

3. AssetBundle을 빌드에는 BuildPipeline.BuildAssetBundles() 같은 간편한 API들이 있다. 이 API들은 상당히 간편하며, 몇가지의 정보만이 필요하다.

 : 모든 AssetBundle들을 위한 output path (*역자주 : 단일 패스를 써야하는 듯.)

 : BuildAssetBundleOptions이 있는데 아래에서 상세히 설명하겠다.

 : 이전과 같은 BuildTarget

 : 또한 AssetBundle들에 asset들로부터 하나의 맵을 포함하고 있는 AssetBundleBuild의 배열을 제공하는 overloaded version(?)을 가진다.

 

4. asset database 안에 AssetBundle 이름을 컨트롤 하는 API들

 : AssetDatabase.GetAllAssetBundleNames() : asset database안의 모든 AssetBundle 이름들을 돌려준다.

 : AssetDatabase.GetAssetPathsFromAssetBundle : 전달한 AssetBundle안에  있는 asset paths marked 를 돌려준다.

 : AssetDatabase.RemoveAssetBundleName() : asset database안에서, 전달한 AssetBundle 이름을 삭제한다.

 : AssetDatabase.GetUnusedAssetBundleNames() : 사용되지 않는 AssetBundle 이름을 돌려준다.

 : AssetDatabase.RemoveUnusedAssetBundleNames() : asset database안의 사용되지 않는 모든 AssetBundle 이름들을 삭제한다.

 : AssetPostProcessor.OnPostprocessAssetbundleNameChanged : callback함수. user가 어떤 asset의 AssetBundle 이름을 변경하면 호출된다.

 

5. BuildAssetBundleOptions

 : CollectDependencies 와  DeterministicAssetBundle 은 항상 enable되어야 한다.

 : CompleteAssets 은 무시한다.(ingored로 되어 있는데, ignored의 typo인 듯) 우리는 항상 objects보다 assets을 우선시하여 시작하기 때문이며, 이건 무조건 기본이라고 봐야 한다.

 : ForceRebuildAssetBundle가 추가되었다. assets들에 어떤 변화가 없다고 하더라도, 이 플래그를 세팅하여 AssetBundle들을 강제로 다시 빌드할 수 있다.

 : IngoreTypeTreeChanges가 추가되었다. type tree가 변경되었더라도, 이 플레그를 설정하면, type tree의 변경을 무시할 수 있다. (IngoreTyp .. 이것도 IgnoreTypeTreeChanges인 듯.)

 : DisableWriteTypeTree 는 IngoreTypeTreeChanges와 대치되는 옵션인데, 만약 type tree를 비활성화 하면, type tree의 변화를 무시할 수 없다. (? 이 옵션을 활성화 하면, 위 옵션을 true로 설정할 수 없다는 말인가?) 

 

6. Manifest file. 모든 AssetBundle를 위해 아래 정보가 포함된 manifest file을 생성한다.

 : manifest file은 AssetBundle 다음에 생성한다.

 : CRC

 : Asset file hash. 증분 빌드 체크를 위해 사용된, 이 AssetBundle안에 포함된 모든 assets을 위한 단일 hash.

 : type tree hash.  증분 빌드 체크를 위해 사용된, 이 AssetBundle안에 포함된 모든 types을 위한 단일 hash.

 : Class types. 이 AssetBundle에 포함된 모든 class types. 이것들은 type tree 증분 빌드 체크를 진행할 때 새로운 단일 hash를 얻기위해 사용된다.

 : Asset names. 이 AssetBundle에 명시적으로 포함된 모든 assets.

 : 연관된 AssetBundle names. 이 AssetBundle이 의존하는 모든 AssetBundles.

 : 이 manifest file은 runtime에서는 필요없고, 오직 증분빌드를 위해서만 사용된다.

 

7. 단일 manifest file. 모든 AssetBundles과 그 AssetBundle이 의존하는 모든 것들을 포함하는 단일 manifest file을 생성한다.

 

8. 단일 manifest AssetBundle. 이것은 단지 아래 API들을 가지고 있는 AssetBundleManifest object를 가진다. 

 : GetAllAssetBundles(). 해당 빌드안의 모든 AssetBundle 이름을 돌려준다.

 : GetDirectDependencies(). 직접적인 의존관계가 잇는 AssetBundle 이름들을 돌려준다.

 : GetAllDependencies(). 의존관계에 있는 모든 AssetBundle 이름들을 돌려준다.

 : GetAssetBundleHash(string). 명시한 AssetBundle을 위한 해쉬값을 돌려준다.

 : GetAllAssetBundlesWithVariant(). variant를 가진 모든 AssetBundle들을 돌려준다.

 

9. AssetBundle loading APIs가 변경되었다.

 : AssetBundle.GetAllAssetNames(). 해당 AssetBundle안에 모든 asset 이름들을 돌려준다.

 : AssetBundle.GetAllScenePaths(). 만약 stream 방식의 scene AssetBundle이라면 모든 scene asset paths를 돌려준다.

 : AssetBundle.LoadAsset(). AssetBundle로부터 asset을 로드한다.

 : AssetBundle.LoadAllAssets(). (*역자주 : loadallassets이 있다면 loadasset은 일부만 로딩하나? 인자도 없는데 뭘 기준으로??)

 : AssetBundle.LoadAssetWithSubAssets()

 : 비동기 버전도 제공됨.

 : 더 이상 component type이 리턴되지 않을거다. 처음에 게임 오브젝트를 로드한 후 오브젝트의 component를 살펴보길 바란다.

  

10. Typetree 기본적으로 AssetBundle에 기록된다. Metro는 예외인데, 이건 다른 병렬화 솔루션을 가지기 때문이다. (typetree가 뭔지 모르니, 뭔소린지 정확히 이해가 안되네 --)


아래는 새로운 AssetBundle 빌드 시스템을 어떻게 사용하는지에 대한 기본 사용법이다. 


1. 더 이상 복잡한 빌드 스크립트는 필요없다.


2. Unity 종속성을 관린한다.

 : 이것은 유니티가 모든 종속관계를 알고 있고, 사용자 대신해서 조정할 것이기에 PushAssetDependencies/PopAssetDependencies 함수들을 사용할 때 종속관계를 더 이상 조정할 필요가 없다는 의미다. 요건 니 노동시간을 더 줄여줄거야.


3. 증분 빌드 체크는 실제 변경된 AssetBundle를 rebuild 하는데만 필요하다는 의미다. 이건 두개의 parts를 포함하는데..

 : asset file 변화를 위한 증분 빌드 체크. 해당 AssetBundle에서 모든 assets을 위한 단일 hash를 만들다. AssetBundle안에 assets이 변경되었을 때만 변경되며, rebuild된다.

 : type tree 변화를 위한 증분 빌드 체크. AssetBundle안의 type trees를 위해 단일 hash를 생성하며, 기본적으로 변경되었을 때만 rebuild한다. 하지만 IgnoreTypeTreeChanges flag를 세팅하면 tyoe tree 변경을 무시할 수 있다.

 

4. 종속관계에 있는 모든 AssetBundle을 강제로 rebuild 하지마라.

 : 종속관계의 오브젝트를 저장하는 방법을 변경했다. 이는 당신이 종속관계에 있는 모든 AssetBundle들을 rebuild하지 않지 않아도 되게 해준다.

 : 샘플을 살펴보라. 여기에 어떤 텍스쳐를 포함하는 하나의 매터리얼을 가진 cube prefab이 있다. 만악 CubeAssetBundle안에 cube prefab을 mark하고 MaterialAssetBundle안에 매터리얼이 markgkaus, 해당 material의 texture가 변한다. 이전 빌드 시스템에서는, 종속된 오브젝트들을 리빌드 해야 했기에,  CubeAssetBundle 와 MaterialAssetBundle 모두를 rebuild 해야만 했었다. 하지만 새로운 빌드 시스템에서는 단지 CubeAssetBundle을 다시 빌드할 필요없이 MaterialAssetBundle만 리빌드 하면 된다.

 

덧붙임 : 한동안 구 빌드 시스템과 신 빌드 시스템은 공존할거야. 절대 이 두가지를 동시에 사용하지 않도록 해야한다.


AssetBundle Variant


이것에 대해 약간, 설명을 하겠다. Unity 5.0b21부터, 새로운 빌드 시스템에 AssetBundle variant를 지원하는 기능이 있는데, 가상의 assets으로 같은 결과를 만들도록 할 수 있다.


예를들어, “MyAssets.hd”, “MyAssets.sd” (이 두 개의 AssetBundles안에 assets이 정확히 일치함.)와 같은 variant들로 AssetBundle을 만들 수 있다. 이 두개의 variant AssetBundles안에 오브젝트들은 Unity 빌드 pipeline에 의해 보장된, 정확히 일치하는 내부 IDs을 가질 것이다. 그래서 이 두개의 variant AssetBundles는 실행 중 다른 variant extension의 AssetBundles을  독단적인 변경할 수 있다.


AssetBundle variant를 어떻게 세팅하냐면..

1. Unity 5.0 b21의 AssetBundle 이름 UI곁의 UI를 사용해서, 해당 AssetBundle의 다른 이름을 세팅하여 또 다른 UI를 추가한다.

2. AssetImporter.assetBundleVariant. UI 외에, 스크립트를 통해 AssetBundle variant를 설정 할 수 있다.


전체 AssetBundle 이름은 AssetBundle 이름과 variant 이름을 조합하여 생성된다. 예를들어, 만약 어떤 변경된 AssetBundle로 "MyAssets.hd”를 추가하길 원한다면, 당신은 "MyAssets"이라는 AssetBundle이름을 설정하고 AssetBundle variant에 "hd"를 설정해야 한다. 그럼 최종적으로 AssetBundle은 "MyAssets.hd”라는 이름을 가지게 된다.


하지만, 만약 "MyAssets.hd”처럼 AssetBundle 이름을 설정하면, 그땐 variant AssetBundle이 아닌 그냥 일반적인 AssetBundle이 된다. 그리고 이후에는 “MyAssets”+“hd” 와  “MyAssets.hd”+””는 같은 전체 AssetBundle이름을 사용할 수 없기 때문에 공존할 수 없게 된다.


덧붙임 : Editor simulation에서는 호환되지 않는다.


Demo


AssetBundle 시스템의 사용한 시연용으로 새로운 빌드 시스템에 기초한, 데모를 만들었다. 아래 링크에서 해당 데모를 다운 받을 수 있으며, 접속할 수 없으면 unity에 문의 메일 보내라. 그리고 이 데모를 실행하기 위해서는 Unity 5.0 b21이 있어야 해.


http://files.unity3d.com/vincent/assetbundle-demo/users_assetbundle-demo.zip


이 데모에서는 아래 내용을 볼 수 있다.


1. 새로운 빌드 시스템에서 AssetBundles를 빌드 하는 방법

2. 단일 manifest AssetBundle를 사용하는 방법

3. 자동화된 AssetBundle 종속성의 해결책, 로딩 과 언로딩

4. Editor simulation. 이거 활성화 하면, 실제로 빌드하지 않고도 Editor 실행모드에서 AssetBundles를 사용할 수 있다.

5. 모든 AssetBundles를 다운받을 수 있는 장소 옵션 세팅

6. Build pipeline build integration. AssetBundles를 빌드하는 스크립트를 StreamingAssets 폴더에 복사하면, 당신이 플레이어를 빌드할 대 플레이어 데이타 안에 같이 묶어질 수 있다. 플레이어 데이타를 빌드할 때 “AssetBundles/Build Player” 를 사용하길 바란다.

7. WWW.LoadFromCacheOrDownload 신 버전이 제공되며, 다운될 때 128 bit hash를 제공한다. 단일 manifest AssetBundle로부터 해당 hash를 얻을 수 있다.

8. 가상 assets으로 같은 결과를 제공하는 AssetBundle variant (Editor simulation에서는 호환되지 않음.)


좀 더 상세한 정보를 얻으려면 demo 프로젝트의 README 파일을 참고하길 바란다. 


   

반응형