Skip to content

Instantly share code, notes, and snippets.

@ssabii
Last active December 22, 2022 17:47
Show Gist options
  • Save ssabii/3ab05c09ff543c7130696e25ff1bea1b to your computer and use it in GitHub Desktop.
Save ssabii/3ab05c09ff543c7130696e25ff1bea1b to your computer and use it in GitHub Desktop.
UnityWebRequest로 에셋번들을 비동기 방식으로 로드하는 코드
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class LoadAssetBundlesFromUnityWebRequestAsync : MonoBehaviour {
// Use this for initialization
void Start () {
StartCoroutine(LoadAssetBundleAsync());
}
IEnumerator LoadAssetBundleAsync()
{
string uri = "file:///" + Application.dataPath + "/AssetBundles/bundle";
UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri);
yield return request.SendWebRequest();
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
AssetBundleRequest bundleRequest = bundle.LoadAssetAsync<GameObject>("Stone");
yield return bundleRequest;
var prefab = bundleRequest.asset;
Instantiate(prefab);
bundleRequest = bundle.LoadAssetAsync<GameObject>("Brick");
yield return bundleRequest;
prefab = bundleRequest.asset;
Instantiate(prefab);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment