Last active
December 22, 2022 17:47
-
-
Save ssabii/3ab05c09ff543c7130696e25ff1bea1b to your computer and use it in GitHub Desktop.
UnityWebRequest로 에셋번들을 비동기 방식으로 로드하는 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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