에셋번들 예제
http://u3d.as/1qS
에셋번들 관련 글
파일에 쓰는법
var cache = new System.IO.FileStream( 저장할 경로 , System.IO.FileMode.Create);
cache.Write(download.bytes, 0, download.bytes.Length);
cache.Close();
조금은 하드코딩이 되겠지만요 ^^;
제가 사용한 방법을 예를 들자면 에셋에서 그림파일을 불러온후
그것을 PNG로 변환 설정한후에 byte[]형으로 변환해서
FileStream을 사용해 Write해주는 방식으로 처리 했어요.
다른 한가지 방법으로는 zip를 이용해서 다운로드 한후 압축을 풀어 사용하는 방법도 있습니다.
전 요즘엔 이 방법을 더 많이 쓰는것 같군요 ^^;
zip 파일로 다운로드를 만든 경우에는 Object로 불러 오신후 그것을
(GameObject)Instantiate(불러온 오브젝트, 좌표, Quaternion회전) 등으로 사용할 수 있을듯 합니다.
테스트는 안해 봤어요 ^^;;
{
string[] assetName =
{
"assets/resources/object/mobobject/n2010_wolf/face/n2010f01.png",
"assets/resources/object/mobobject/n2010_wolf/n2010.png",
return assetName;
}
public static void BuildAssetWindows()
{
string[] assetName = AssetBundleModule.GetAssetNameList();
for (int i = 0; i < assetName.Length; ++i)
{
asset[i] = AssetDatabase.LoadMainAssetAtPath(assetName[i]);
assetName[i] = Regex.Replace(assetName[i], @"(?i)Assets/Resources/", "");
assetName[i] = assetName[i].Remove(assetName[i].LastIndexOf("."));
Debug.Log(assetName[i]);
}
}
{
string assetPath = GetAssetBundleWebURL();
Debug.Log(assetPath);
m_WWW = WWW.LoadFromCacheOrDownload(assetPath, m_nAssetBundleVersion);
}
else
{
string assetPath = GetAssetBundlePath();
Debug.Log(assetPath);
m_WWW = new WWW(assetPath);
}
m_WWW.Dispose();
m_WWW = null;
if (findObject == null)
{
Debug.Log("FindAssetName not exists object : " + name + " / type : " + type.ToString());
}
return findObject;
http://botta.tistory.com/38 이 사이트를 참고하셔서 만들어보세요~ 그리고
public IEnumerator OnLoadAssetBundle()
{
m_WWW = new WWW("file://" + Application.dataPath + "/../" + "애셋번들");
yield return m_WWW;
m_AssetBundle = m_WWW.assetBundle;
m_WWW.Dispose();
m_WWW = null;
Texture m_Tex1 = (Texture)m_AssetBundle.Load("CFa0.png", typeof(Texture));
}
C#을 기준으로 설명 드릴께요.
먼저 변수선언으로
int _gender = 0;
int _job = 0;
Texture2D _texture = null;
AssetBundle _assetBundle = null;
를 주시고,
함수 한개를 만들어서
IEnumerator gameHeroImageLoad (int argGender, int argJob) {
WWW _www = new WWW("file://" + "디렉토리와 파일명");
yield return _www;
_assetBundle = _www.assetBundle;
string _tmpHeroImageName = argGender + "-" + argJob + "-Texture";
if (_assetBundle.Gontains(_tmpHeroImageName)) {
_texture = (Texture2D)_assetBundle.Load(_tmpHeroImageName);
}
}
Update () 에서 특정 조건일때 위에 함수를 불러 오게되면 _texture에
이미지가 들어 가겠죠.
그후 OnGUI ()에서 _texture가 null일때와 아닐때의 표시 부분을 바꿔 주시면 될듯 합니다.
단 한가지 주의할 점은 그래픽을 다른 그래픽으로 바꾸시고 싶으시다면,
void deleteGameObject () {
_texture = null;
_assetBundle.Unload(true);
_assetBundle = null;
}
이 함수를 부르신 후에 다시 gameHeroImageLoad를 불러와 주시면 됩니다.
번들을 만들때는 이름에 주의 하셔서 성별-직업-Texture와 같이 png파일을 저장해 주시면 될 것 같습니다.
그냥 머리속의 프로그램을 적는 거니 버그가 있을 수 있습니다.
에셋번들 관련 링크
api
http://docs.unity3d.com/ScriptReference/AssetBundle.html
menual
http://docs.unity3d.com/Manual/AssetBundlesIntro.html
'유니티 > Note' 카테고리의 다른 글
| 유니티 관련 노트. (0) | 2014.08.11 |
|---|---|
| [펌][ Unity3D ] 모바일(안드로이드) 파일생성 및 읽고 쓰기 Unity3D (0) | 2014.07.07 |
| 에셋번들 관련 글 및 링크 모음 (0) | 2014.07.07 |
| 안드로이드 스튜디오를 사용시 기존 이클립스 폴더 불러오기. (0) | 2014.06.26 |
| 기본적인 프로그래머.. (0) | 2014.06.22 |
| 유니티 재귀함수의 예(헥사, 캔디팡) -Recursive Methods (0) | 2014.06.05 |


