Unity Asset Bundle Learning - Loading Network Resources

Yesterday I debugged and loaded local resources.
Unity Asset Bundle Learning - Loading local resources

Try using Asset Bundle to load network data today

Then I followed the documentation and found that there was a problem referencing the namespace and kept getting errors. If
it didn't work according to the documentation, I just checked it on Baidu.

After checking a lot about this thing, I found a lot of senior experience. I just copied the code and used it. The following paragraph is for testing and there is no problem.

public IEnumerator HttpLoadAB()
{ //Download UnityWebRequest on the server request = UnityWebRequestAssetBundle.GetAssetBundle("http://xxx.com/AssetBundles/weapon.unity3d");//The address of the resource is yielded on your own server return request.SendWebRequest() ; if (string.IsNullOrEmpty(request.error) == false)//Determine whether there is an error in the download, request.error represents the error message { Debug.Log(request.error);//Output error yield break;//Exit Ctrip } //Another way to obtain resources is to directly obtain the things downloaded by UnityWebRequest and then force convert them to DownloadHandlerAssetBundle, and then obtain the AssetBundle AssetBundle ab = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle; Sprite prefab = ab.LoadAsset( "icon-weapon"); im_weapon.sprite = prefab; }












I encountered a small problem during debugging and recorded it
because the resource ended with .unity3d and was placed in the corresponding folder on the server. After direct access, I found that it kept reporting 404.
This was because the MIME type of the IIS server was not added.

Insert image description here
Double-click to open
, then click Add in the upper right corner
to add a new type.
Insert image description here
Then you can access it
and then debug normally~

Subsequently, debug and load the network AssetBundle resources to the local and then load
March 02, 2023 10:37:19

Guess you like

Origin blog.csdn.net/qq_32065601/article/details/129295030