0

I get the assetbundle by using UnityWebRequest GetAssetBundle(string uri, uint version, uint crc);

but Application.streamingAssetsPath is empty....

where is downloaded assetbundle and how to loaded downloaded assetbundle?

my Unity version is 2017.3

And add Question.

AssetBundle manifestBundle = AssetBundle.LoadFromFile(manifestBundlePath); AssetBundleManifest manifest = manifestBundle.LoadAsset("AssetBundleManifest"); What is manifestBundlePath and How to access and get this path?

How can I access downloaded assetbundles before use UnityWebRequest.GetAssetBundle

if you suggest the way, I'm really thanks to you.

BlueStar
  • 405
  • 1
  • 6
  • 10

2 Answers2

0

From the documentation:

If you have a "StreamingAssets" folder in the Assets folder of your project, it will be copied to your player builds and be present in the path given by Application.streamingAssetsPath.

So presumably if you do not have a "StreamingAssets" folder in your Assets folder, then it will be blank.

And for your second question, what is the manifestBundlePath, well, again, from the documentation:

path - Path of the file on disk.

And you'd get it in the same way as the example:

Path.Combine(Application.streamingAssetsPath, "myassetBundle")

Where "myassetBundle" is the name of the bundle.

Similarly when calling LoadAsset("AssetBundleManifest");, "AssetBundleManifest" is the name of the asset to load.

0

That's not how it works; if you are using GetAssetBundle then you must load the asset bundle using the response, as the documentation shows:

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class MyBehaviour : MonoBehaviour {
    void Start() {
        StartCoroutine(GetAssetBundle());
    }

    IEnumerator GetAssetBundle() {
        UnityWebRequest www = UnityWebRequest.GetAssetBundle("http://www.my-server.com/myData.unity3d");
        yield return www.SendWebRequest();

        if(www.isNetworkError || www.isHttpError) {
            Debug.Log(www.error);
        }
        else {

            // !!!!!! <--- Notice we do not load the asset bundle from file.
            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
        }
    }
}

If you want to manually download and save the file, do it like this:

using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;

public class FileDownloader : MonoBehaviour {

    void Start () {
        StartCoroutine(DownloadFile());
    }

    IEnumerator DownloadFile() {
        var uwr = new UnityWebRequest("http://www.my-server.com/myData.unity3d", UnityWebRequest.kHttpVerbGET);
        string path = Path.Combine(Application.persistentDataPath, "myData.unity3d");
        uwr.downloadHandler = new DownloadHandlerFile(path);
        yield return uwr.SendWebRequest();
        if (uwr.isNetworkError || uwr.isHttpError)
            Debug.LogError(uwr.error);
        else {
            // !!! <-- Now we have a path to the downloaded asset
            Debug.Log("File successfully downloaded and saved to " + path);
            var myLoadedAssetBundle = AssetBundle.LoadFromFile(path); 

            // Matches some 'Resources/MyObject.prefab'
            var prefab = myLoadedAssetBundle.LoadAsset.<GameObject>("MyObject");
            Instantiate(prefab);
        }             
    }
}
Doug
  • 32,844
  • 38
  • 166
  • 222