출처 : http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_Lecture&page=1&sn1=&divpage=1&sn=on&ss=on&sc=on&keyword=%C0%AF%B4%CF%C6%BC&select_arrange=last_comment&desc=desc&no=309
에셋 번들을 만들어야 하는데 파일 하나하나 찍어서 만들기가 너무 귀찮았습니다.
플랫폼마다 똑같은 노가다를 반복 해야 한다고 생각하니 눈앞이 캄캄하더군요.
그래서 텍스트 파일에 리스트를 쭉 적어놓고 읽어와서 일괄 생성하게 만들었습니다.
아래와 같이 파일의 경로를 쭉 적어줍니다.
patch_list.txt 로 저장을 하고 위치는 Resources폴더 아래에 둡니다.
Resources/Sound/main.ogg
Resources/Sound/fire.wav
Resources/character/human.prefab
Resources/character/lion.prefab
Resources/ui/shop.prefab
.
.
.
[Resources/patch_list.txt의 내용]
소스코드는 Assets/Editor 밑에 xxx.cs 로 넣어놓습니다. 파일 이름은 아무거나 넣어도 됩니다.
·미리보기 | 소스복사·
- [MenuItem("Assets/Generate All from file(Windows)")] // 메뉴가 들어갈 위치입니다. Assets메뉴 하위.
- static void GenerateAll()
- {
- // 빌드 타겟은 적절하게 맞춰주면 되겠죠.
- ExportAll(BuildTarget.StandaloneWindows);
- }
- static void ExportAll(BuildTarget target)
- {
- // 리스트를 읽어와서 줄 단위로 분리 해 줍니다.
- TextAsset filelist_obj = Resources.Load("patch_list", typeof(TextAsset)) as TextAsset;
- string[] filelist = filelist_obj.text.Split('\n');
- foreach (string original_path in filelist)
- {
- // *중요함! 개행 문자를 제거 해 줍니다.
- string path = original_path.Trim('\n');
- path = path.Trim('\r');
- if (path.Length <= 0)
- {
- continue;
- }
- // 확장자, 경로 다 빼고 파일 이름만 쏙 빼옵니다.
- int last_split_pos = path.LastIndexOf('/') + 1;
- int extend_length = path.Length - path.LastIndexOf('.');
- string filename = path.Substring(last_split_pos, (path.Length - last_split_pos) - extend_length);
- // 번들 파일이 생성될 경로 입니다.
- // 프로젝트 상위 폴더에 "patch/(플랫폼명)" 형태의 폴더를 미리 만들어 놓아야 합니다.
- // 예)
- // d:/project/patch/Android <- 번들 파일이 생성될 폴더
- // d:/project/gamecodi <- 프로젝트 폴더
- // d:/project/gamecodi/Assets
- string output_path = string.Format("../patch/{0}/{1}.unity3d", target.ToString(), filename);
- // 리스트에 기입된 경로에서 오브젝트를 로드합니다.
- string included_path = "Assets/" + path;
- UnityEngine.Object obj = Resources.LoadAssetAtPath(included_path, typeof(UnityEngine.Object));
- if (obj == null)
- {
- Debug.LogError("Cannot find the resource. " + included_path);
- continue;
- }
- // 생성!
- BuildPipeline.BuildAssetBundle(obj, null, output_path,
- BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,
- target);
- Debug.Log("completed... : " + included_path);
- }
- }
파일 경로를 읽어온 뒤 개행 문자를 제거 해 주는것이 굉장히 중요합니다.
이것을 빼먹고 했더니 리소스 로딩이 실패나서 한참 고생했습니다.ㅠ_ㅠ
이렇게 만들어 놓고 플랫폼만 바꿔서 클릭 한번만 하면 되겠습니다.
끝~
'잡다한것들전부 > 팁' 카테고리의 다른 글
| [펌] 유니티 디바이스 화면에 디버깅 콘솔 찍기 (0) | 2014.01.16 |
|---|---|
| [펌] 유니티3D Conditional Attribute 사용 (0) | 2014.01.16 |
| [펌] 유니티 엔진 - 텍스트 파일을 이용하여 에셋 번들 한꺼번에 생성 하기 (0) | 2014.01.16 |
| [펌] 유니티엔진 - 유니티 스키닝 설정. (0) | 2014.01.16 |
| [펌] 유니티 안드로이드 빌링 api3 적용 팁입니다. (0) | 2014.01.16 |
| [펌] 유니티 엔진 팁 - 광고 모듈 붙이기 (0) | 2014.01.16 |
Trackback 0 And
Comment 0


