Asseet Bundle 샘플을 만들 때의 노트
10560 단어 Unity
사용된 Unity 버전
5.3.2f
AssetBundle 소개
AsseetBundle 만들기
1. AssetBundle 이름 표시
AssetBundle에 포함된 디렉토리에 이름을 표시합니다.
2. Editor Script 실행
AsseetBundle 생성을 위한 스크립트 만들기
EDITOr 폴더에 배치됩니다.
ExportAssetBundle.cs
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
public class ExportAssetBundle
{
[MenuItem("Export/AssetBundle")]
static void Export()
{
Directory.CreateDirectory(Application.streamingAssetsPath);
BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath);
}
}
이 스크립트가 EDITOr 폴더에 있는 경우Unity 메뉴에 Export 항목이 추가되었습니다.
Export->AsseetBund를 선택한 후
AssetBundle 생성 처리를 수행합니다.
3. 서버에 업로드
위 스크립트를 실행한 후
StreamingAsset 폴더가 생성되었기 때문에
이 폴더를 서버에 업로드합니다.
AssetBundle(서버) 로드
서버의 AssetBundle에서 리소스를 로드하는 절차는 다음과 같습니다.
CachingLoadExample.cs
using UnityEngine;
using System.Collections;
public class CachingLoadExample : MonoBehaviour
{
string bundleURL = "http://localhost:9000/assets/StreamingAssets/sprites";
string assetName = "Test";
int version = 0;
void Start()
{
StartCoroutine(DownloadAndCache());
}
IEnumerator DownloadAndCache()
{
while(!Caching.ready)
yield return null;
using(WWW www = WWW.LoadFromCacheOrDownload(bundleURL, version)) {
yield return www;
if (www.error != null) {
throw new UnityException("WWW download had an error" + www.error);
}
AssetBundle bundle = www.assetBundle;
Instantiate(bundle.LoadAsset(assetName));
bundle.Unload(false);
}
}
}
AssetBundle(로컬) 로드
Unity 프로젝트 내의 StreamingAssets에서 에셋을 읽을 수도 있습니다.
AsseetBundle의 읽기는 AssetBundle입니다.LoadFrom FileAsync 방법을 사용합니다.
LoadAssetBundle.csusing UnityEngine;
using System.Collections;
public class LoadAssetBundle : MonoBehaviour
{
string assetName = "Test";
string AssetPath {
get {
return Application.streamingAssetsPath + "/sprites";
}
}
IEnumerator Start()
{
var resultAssetBundle = AssetBundle.LoadFromFileAsync(AssetPath);
yield return new WaitWhile(() => resultAssetBundle.isDone == false);
var assetbundle = resultAssetBundle.assetBundle;
var resultObject = assetbundle.LoadAssetAsync<GameObject>(assetName);
yield return new WaitWhile(() => resultObject.isDone == false);
GameObject.Instantiate(resultObject.asset);
assetbundle.Unload(false);
}
}
참고 자료
WWW
http://docs.unity3d.com/ja/current/ScriptReference/WWW.html
AssetBundle
http://docs.unity3d.com/ja/current/ScriptReference/AssetBundle.html
Unity 5의 Asseet Bund에 대해서 짧게 정리를 해봤어요.
http://www.slideshare.net/monry84/20150522-31-unity
[Unity] Unity 5.3에서 Asseet Bundle까지의 변화... 정리.
http://tsubakit1.hateblo.jp/entry/2015/12/16/233336
Unity 5의 새로운 AssetBundle 기능을 사용하여 서버에서 AssetBundle 다운로드
http://kazuooooo.hatenablog.com/entry/2015/06/14/150019
Reference
이 문제에 관하여(Asseet Bundle 샘플을 만들 때의 노트), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/uchiko/items/91de62f4cc2d243b479f
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
using UnityEngine;
using System.Collections;
public class LoadAssetBundle : MonoBehaviour
{
string assetName = "Test";
string AssetPath {
get {
return Application.streamingAssetsPath + "/sprites";
}
}
IEnumerator Start()
{
var resultAssetBundle = AssetBundle.LoadFromFileAsync(AssetPath);
yield return new WaitWhile(() => resultAssetBundle.isDone == false);
var assetbundle = resultAssetBundle.assetBundle;
var resultObject = assetbundle.LoadAssetAsync<GameObject>(assetName);
yield return new WaitWhile(() => resultObject.isDone == false);
GameObject.Instantiate(resultObject.asset);
assetbundle.Unload(false);
}
}
WWW
http://docs.unity3d.com/ja/current/ScriptReference/WWW.html
AssetBundle
http://docs.unity3d.com/ja/current/ScriptReference/AssetBundle.html
Unity 5의 Asseet Bund에 대해서 짧게 정리를 해봤어요.
http://www.slideshare.net/monry84/20150522-31-unity
[Unity] Unity 5.3에서 Asseet Bundle까지의 변화... 정리.
http://tsubakit1.hateblo.jp/entry/2015/12/16/233336
Unity 5의 새로운 AssetBundle 기능을 사용하여 서버에서 AssetBundle 다운로드
http://kazuooooo.hatenablog.com/entry/2015/06/14/150019
Reference
이 문제에 관하여(Asseet Bundle 샘플을 만들 때의 노트), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/uchiko/items/91de62f4cc2d243b479f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)