참고: UNet은 지원이 중단되었으며 향후 Unity에서 삭제될 예정입니다. 현재 새로운 시스템이 개발 중입니다. 자세한 내용과 다음 단계는 이 블로그 포스트를 참조하십시오. |
원격 서버에서 에셋 번들을 다운로드하기 위해 UnityWebRequest.GetAssetBundle
을 사용할 수 있습니다. 이 함수는 데이터를 내부 버퍼로 스트리밍하며, 워커 스레드에서 에셋 번들의 데이터를 디코드하고 압축을 풉니다.
함수의 인수는 여러 가지 형태입니다. 가장 간단한 형태는 에셋 번들을 다운로드해야 하는 URL만 인수로 사용하는 것입니다. 다운로드된 데이터의 무결성을 확인하기 위해 검사 합계를 제공할 수도 있습니다.
또는 에셋 번들 캐시 시스템을 사용하고 싶은 경우 버전 번호 또는 Hash128 데이터 구조를 제공할 수도 있습니다. 이는 WWW.LoadFromCacheOrDownload
를 통해 이전 시스템에 제공된 버전 번호 또는 Hash128 오브젝트
와 동일합니다.
UnityWebRequest
를 생성하며 타겟 URL을 제공된 URL 인수로 설정합니다. 또한 HTTP 동사 GET
을 설정하지만 다른 플래그나 커스텀 헤더는 설정하지 않습니다.DownloadHandlerAssetBundle
을 UnityWebRequest
에 연결합니다. 이 다운로드 핸들러는 특별한 assetBundle
프로퍼티를 가지고 있으며, 이 프로퍼티는 충분한 데이터가 다운로드되고 디코드된 후 에셋 번들을 추출하여 에셋 번들 내 리소스에 대한 액세스를 허용하기 위해 사용할 수 있습니다.Hash128
오브젝트를 인수로 제공하면 이 함수는 또한 이 인수를DownloadHandlerAssetBundle
에 전달합니다. 그런 다음, 다운로드 핸들러는 캐시 시스템을 활용합니다.using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class MyBehaviour : MonoBehaviour {
void Start() {
StartCoroutine(GetAssetBundle());
}
IEnumerator GetAssetBundle() {
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle("http://www.my-server.com/myData.unity3d");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success) {
Debug.Log(www.error);
}
else {
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
}
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.