블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-20 00:00

Unity AssetBundle Dependencies

In the last few weeks I’ve spent quite a lot of time with Unity’s Asset Bundle system. Understanding how dependencies were tracked. What determines GC cleanup of assets and understanding why the editor profiler produces particular results has been a bit of a struggle. I’m lucky enough to work for a group that allows me to have access to the Unity source code however so this has probably been slightly less painful than it has been for others going down this same path.

First, I’d like to acknowledge what appears to be the most useful piece of Unity Answers information that I’ve come across, located here. This seems to explain the general mechanics of how to include dependencies using the push and then pop method in an editor script.

For my purposes, I created a test project that contained several prefabs all containing simple GUI elements. These elements all used the same fonts and referenced the same textures. This was to verify that, in the editor profiler and in instruments, assets were in fact being shared.

I’ve included my example editor script below to demonstrate some of the methods I used for packing the bundles. In my case, I am traversing all assets in my prefab folder and treating elements with the word “Global” in their name as shared. If I were to have many dependency bundles instead of the one that I have in this example I would have to sort the order in which I am packing these bundles.

using UnityEngine;
using UnityEditor;

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

public class AssetBundleBuild : MonoBehaviour
{
    [MenuItem("AssetBundle/Build Bundles")]
    private static void BuildBundles()
    {
        DirectoryInfo directory = new DirectoryInfo(Application.dataPath + "/Prefabs");
        FileInfo[] files = directory.GetFiles("*.prefab", SearchOption.AllDirectories);

        bool shouldPush;

        BuildPipeline.PushAssetDependencies();
        foreach (FileInfo f in files)
        {
            shouldPush = !f.Name.Contains("Global");
            if (shouldPush)
            {
                BuildPipeline.PushAssetDependencies();
            }

            // Get each asset path
            string path = Application.dataPath + "/Bundles/" + f.Name.Substring(0, f.Name.LastIndexOf(".")) + ".bundle";
            string assetPath = f.FullName.Substring(f.FullName.IndexOf("Assets", f.FullName.Length - f.FullName.IndexOf("Assets")));

            Object asset = AssetDatabase.LoadMainAssetAtPath(assetPath);
            //Debug.Log("Asset to pack " + asset + " , " + asset.name);

            BuildAssetBundleOptions options = 
                BuildAssetBundleOptions.DisableWriteTypeTree | 
                BuildAssetBundleOptions.CollectDependencies | 
                BuildAssetBundleOptions.CompleteAssets | 
                BuildAssetBundleOptions.DeterministicAssetBundle;

            if (!shouldPush)
            {
                Object[] d = EditorUtility.CollectDependencies(new Object[] { asset });

                List<Object> dSource = new List<Object>();
                List<string> dNames = new List<string>();

                // In this case I'm attempting to manually collect dependencies for tracking purposes
                // however this does not always seem to be necessary unless you have complex prefab heirarchies
                foreach (Object o in d)
                {
                    if (o != null && !dSource.Contains(o))
                    {
                        Debug.Log(" -- d " + o + " , " + o.name + " , " + o.GetType());

                        dSource.Add(o);
                        dNames.Add(o.name);
                    }
                }

                Debug.Log("::BUILDING DEPENDENCY BUNDLE:: " + asset.name + " , " + dSource.Count);
                BuildPipeline.BuildAssetBundleExplicitAssetNames(
                    dSource.ToArray(), 
                    dNames.ToArray(), 
                    path, 
                    options, 
                    EditorUserBuildSettings.activeBuildTarget);
            }
            else
            {
                Debug.Log("::NON DEPENDENCY:: " + asset.name);
                BuildPipeline.BuildAssetBundleExplicitAssetNames(
                    new Object[] { asset }, 
                    new string[] { asset.name }, 
                    path, 
                    options, 
                    EditorUserBuildSettings.activeBuildTarget);

                if (shouldPush)
                {
                    BuildPipeline.PopAssetDependencies();
                }
            }
        }

        BuildPipeline.PopAssetDependencies();

        Debug.Log("[AssetBundleBuild] Complete.");
    }
}

Now, from the standpoint of packing shared dependencies, this seemed to work with most asset types such as textures or prefabs but when I included fonts, while they wouldn’t be duplicated across multiple bundles, I would always see two copies of my fonts. One set would be flagged as being ‘used by scripts and native code’ and the other would only be flagged as ‘used by native code’. After performing numerous tests, I discovered that upon opening the dependency bundle containing the font I was interested in, if there was a copy of the font in the project directory as well, both versions would be loaded into Resources. I haven’t been able to verify whether this happens on device as well but my inclination is that it only occurs in the editor.

The Problem of the Decompression Buffer

Another problem that became visible when working with large quantities of bundles that (based off of conversations with Unity technical representatives and the 4.2.0b3 beta client) may have changed in such a way as to render the problem less dire is that Unity, as of 4.1.5, allocates an 8mb decompression buffer per each asset bundle being opened. If there is an attempt to parallelize these requests, each request will allocate it’s own decompression buffer. This can be rather disconcerting as one can see how the allocation amount (especially on restricted memory devices) can really get a guy down.

Although 4.2.0b3 seems to be reducing the decompression buffer size down to 0.5mb per bundle the problem of parallelization still persists. The only immediate solution for individuals loading any quantity of bundles seems to be amortizing the requests in such a way as to prevent too much overlap. If someone out there has a suggestion to mitigate this problem otherwise please drop me a line mcelroy.jon[at]gmail.com


출처 : http://blog.jonmcelroy.com/post/55526714506/unity-assetbundle-dependencies

반응형
Posted by blueasa
, |

KGC AssetBundle

2013.09.26
10:30 ~ 11:30


Asset: 유니티에서 게임을 만들떄 필요한 모든 컨텐츠 
AssetBundle? Asset들을 하나로 묶는 기능 
압축 파일 포멧 

LZMA Algorithm 사용 

어셋번들의 중요성 
빌드 사이즈를 줄일수 있다.
게임 패치 (CDN과 같은 서버에 올려놓고 다운받는 형식)
더 낳은 퍼포먼스 (캐시 기능)


Caching이란?
CDN -> Local Disk <-> Unity

캐싱폴더 위치는?

모바일 / PC / 콘솔 : 4기가 캐싱사용가능
웹 : 50MB (캐싱 라이센스) 

캐싱폴더가 다 찬다면?
어셋번들이 사용된 시간을 기준으로 가장 최근에 사용되지 않은 어셋번들 부터 삭제 (Least Rencently Used algorithm )

만약 하드디스크가 꽉 차거나 모든 캐쉬가 사용중이라면?
어셋번들을 캐싱하지 않고 메모리에 올림 (like new WWW())

유니티 버전 호환성과 사이즈 DisableWriteTypeTree

ASsetBundle메모리 

Distory -> UnloadUnuseAssets사용 (런타임시 반복호출시 힉헙 상태 발생 가능성 있음)

프로파일러 사용 권장 


어셋번들의 암호화 
  • Open SSL을 이용해서 어셋번들을 암호화 
  • 암호화된 어셋번들을 텍스트로 변환
  • 전달 방법을 선택 
    • Application포함 
    • 서버에서 다운로드
  • 암호화된 어셋번들을 메모리에서 복호화 (with System.Security.Encrypt)

>>>> Binary 파일 변환과정을 거쳐 암호화를 시킬수 있다.

PC/웹 : 하위 호환성 유지 

안드로이드 / iOS : 호환 할수 있도록 계획 중
Q. 어셋번들과 유니티 버전에서 문제점 (새로 만들어야 한다. 소수점 2째자리 업데이트는 호환 가능 )


어셋사이즈와 해싱된 사이즈가 다른 이유?
어셋번들이 캐싱폴더에 저장될때는 Uncompressed상태에서 자장 ( 압축 풀린 상태 ) -> 보다 빠른 로딩이 가능 


캐싱 용량을 줄이고 싶을때 
Caching.maximumAvailableDiskSpace 사용 

캐싱을 삭제 하고 싶을때(캐싱폴더 전체가 삭제 됨) / 특정 번들을 삭제 하는 방법은 없다. (내년에 추가될 예정)
Caching.CleanCache


"어셋번들을 쪼갤수록 좋다"


Q. CRC알고리즘 ?
Q. 스크립트 포함되어 있는 오브젝트를 어셋번들 공유시 스크립트 동기화 문제



반응형
Posted by blueasa
, |

링크 : http://unitystudy.net/bbs/board.php?bo_table=newwriting&wr_id=357&sca=&sfl=wr_subject&stx=%EC%97%90%EC%85%8B&sop=and

반응형
Posted by blueasa
, |

링크 : AssetBundle 생성부터 패치 및 적용까지. 0 - 관련 링크들 정리


링크 : AssetBundle 생성부터 패치 및 적용까지. 1 - Build AssetBundle


링크 : AssetBundle 생성부터 패치 및 적용까지. 2 - CoRoutine 활용에서 AssetBundle Patch하기



반응형
Posted by blueasa
, |


Link : http://ceolimdevelop.blogspot.kr/2013/11/unity.html



반응형

'Unity3D > AssetBundle' 카테고리의 다른 글

Unity AssetBundle Dependencies  (0) 2014.03.11
AssetBundle 생성부터 패치 및 적용까지.  (0) 2014.02.27
Unity3D - Asset bundle  (0) 2014.02.26
애셋 번들 정리  (0) 2014.02.26
에셋 번들 사용하기  (0) 2014.02.25
Posted by blueasa
, |


Link : http://www.slideshare.net/GreatTed/unity3d-asset-bundle-29583228

반응형
Posted by blueasa
, |


링크 : http://unitystudy.net/bbs/board.php?bo_table=dustin&wr_id=62&sca=&sfl=wr_subject&stx=%EB%B2%88%EB%93%A4&sop=and

반응형
Posted by blueasa
, |

[링크]


에셋 번들 사용하기 첫 번째 - 생성 하기


에셋 번들 사용하기 두 번째 - 에셋 다운로드 받기 (로컬)


에셋 번들 사용하기 세 번째 - 에셋 다운로드 받기 (웹, 서버)


에셋 번들 사용하기 네 번째 - 에셋 다운로드 받기 - 버젼관리


에셋 번들 사용하기 다섯 번째 - 웹에서 모바일(안드로이드)로 다운로드


에셋 번들 사용하기 여섯 번째 - 로컬에서 모바일(안드로이드)로 다운로드


에셋 번들 사용하기 일곱 번째 - 안드로이드 장치에서 에셋 번들 다운로드

반응형

'Unity3D > AssetBundle' 카테고리의 다른 글

Unity3D - Asset bundle  (0) 2014.02.26
애셋 번들 정리  (0) 2014.02.26
AssetBundle (Pro Only)  (0) 2013.06.27
WWW.assetbundle  (0) 2013.06.27
어셋번들 (AssetBundle / BuildPipeline) 생성  (0) 2013.06.27
Posted by blueasa
, |

안드로이드 마켓에 경우 50mb 용량 제한이 있다.

요즘의 게임들은 용량이 큰것들이 많은데 보통 시작시 타이틀화면과 동시에 리소스데이터를 다운받는 형식으로 많이 개발하고 있다.

이것이 바로 인앱 업데이트 방식인데, 이것은 서비스후 운영의 용이성을 도모한다.


그럼 유니티에서 어떻게 구현하여 사용하는지 알아보도록 한다.


그전에 이미 많은 국내 유저들의 포스팅에도 잘 나와있다. 

참고: http://botta.tistory.com/38


어셋번들로 만들어진 파일은 더이상 Resource폴더에 있지 않아도 되니 릴리즈 버젼 빌드시 프로젝트에서 제거해도 무관하다.

하지만 추후 업데이트및 수정작업을 고려해 리소스 백업은 필수라 할수있다.

때문에 Resources와 ResoucesBundle폴더를 생성해서 번들로 만들어져야 하는것들은 다음과 같이 따로 관리 하는것이 좋다.




프리팹도 어셋번들로 만들어 사용할수 있는데 이렇게 만들어진 프리팹의 매시데이터, 텍스쳐, 메트리얼등을 포함하여 함께 가지게 된다.


이때 주의 사항은 같은 메트리얼을 사용하는 여러 오브젝트는 한번에 어셋번들로 만들어야 한다는것이다. 그렇지 않을경우 동일한 메터리얼의 리소스들이 중복이 되어 예기치 못한 에러상황을 만들어 낼 수 있으니 주의 한다.


만드는 법은 매우 간단하다.

Project패널에서 어셋번들로 만들 오브젝트의 우클릭을 하게 되면 다음과 같은 메뉴가 나온다. 


그냥 나오는것은 아니다 

CreateAssetBundle스크립트 파일을 Editor에 추가해 줘야 한다.


내용은 별거 없다.


using UnityEngine;

using System.Collections;

using UnityEditor;

using System;

using System.IO;


public class CreateAssetBundle : MonoBehaviour {

String str;

}


public class cre :MonoBehaviour

{

 [MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]

    static void ExportResourceNoTrack () {

        // Bring up save panel

        string path = EditorUtility.SaveFilePanel ("Save Resource""""New Resource""bfbundle");

        if (path.Length != 0) {

            // Build the resource file from the active selection.

            BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path,BuildAssetBundleOptions.CollectDependencies, BuildTarget.iPhone);

        }

    }

}



다음의 우클릭 하면 나오는 메뉴는 이부분 인것이다.

 [MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]




번들로 만들어지게 되면 다음과 같이 파일명을 적은후 저장하게 된다.




이때 생성되는 확장자명은 임의로 설정할수있다.







다음은 웹에 올려 놓고 불러오는 부분을 확인해본다.




웹서버에 만든 어셋번들 파일을 올려놓는다.



WWW를 통해 로드 하게 되면 다음과 같이 생성하여 사용 할 수 있다.






다음 API를 확인하면 금방 예제를 만들어 볼수 있을듯 하다.


http://www.devkorea.co.kr/reference/Documentation/ScriptReference/AssetBundle.html






AssetBundleObject로 부터 상속됨

AssetBundles은 사용자로 하여금 추가적인 에셋을 WWW 클래스를 통하여 스트리밍을 하고 런타임에 인스턴스를 생성할 수 있게 해줍니다. AssetBundles은 BuildPipeline.BuildAssetBundle을 통해 생성됩니다.

참고: WWW.assetBundleLoading Resources at RuntimeBuildPipeline.BuildPlayer.

function Start () {
var www = WWW ("http://myserver/myBundle.unity3d");
yield www;
// 지정된 메인 에셋을 가져다가 인스턴스를 생성합니다.
Instantiate(www.assetBundle.mainAsset);
}



출처 : http://smilejsu.tistory.com/494

반응형

'Unity3D > AssetBundle' 카테고리의 다른 글

애셋 번들 정리  (0) 2014.02.26
에셋 번들 사용하기  (0) 2014.02.25
WWW.assetbundle  (0) 2013.06.27
어셋번들 (AssetBundle / BuildPipeline) 생성  (0) 2013.06.27
유니티 어셋번들 (AssetBundle)  (0) 2013.06.27
Posted by blueasa
, |

WWW.assetbundle

Unity3D/AssetBundle / 2013. 6. 27. 11:48

http://www.devkorea.co.kr/reference/Documentation/ScriptReference/AssetBundle.html


인앱 업데이트부분을 개발하면서 있었던 문제점?! 들을 포스팅 합니다.


게임이 시작되기전에 업데이트 받아야할 목록들은 크게 데이터와 그래픽리소스로 구분되어 집니다.


이때 WWW를 통해 로드 하게되는데 Editor에서 만들어진 Bundle데이터가 아닐경우 WWW.assetbundle은 null값을 가지는것이 문제였습니다.


유니티 엔진 내부적으로 WWW.assetbundle을 사용하게 되면 번들데이터를 로드 하는것으로 생각합니다.


때문에 WWW를 통해 데이터를 로드 할경우 WWW.assetbundle 은 null값을 가지게 됨으로 이부분을 생각 해서 메니저 클래스를 제작 해야 합니다.



출처 : http://smilejsu.tistory.com/496

반응형

'Unity3D > AssetBundle' 카테고리의 다른 글

애셋 번들 정리  (0) 2014.02.26
에셋 번들 사용하기  (0) 2014.02.25
AssetBundle (Pro Only)  (0) 2013.06.27
어셋번들 (AssetBundle / BuildPipeline) 생성  (0) 2013.06.27
유니티 어셋번들 (AssetBundle)  (0) 2013.06.27
Posted by blueasa
, |