Most platforms (Unity Editor, Windows, Linux players) use
Application.dataPath + "/StreamingAssets"
macOS player uses
Application.dataPath + "/Resources/Data/StreamingAssets"
iOS uses
Application.dataPath + "/Raw"
Android uses files inside a compressed APK/JAR file,
"jar:file://" + Application.dataPath + "!/assets"
Android下加载bundle资源不需要通过WWW下载,可以直接加载资源。
加载时只需要修改一下路径既可以
"jar:file://" + Application.dataPath + "!/assets"
加载示例如下:
- private void LoadAssetBundleTexture()
- {
- if (m_rawImage == null)
- {
- return;
- }
-
- // 资源路径
- var bundlePath = "jar:file://" + Application.dataPath + "!/assets/" + m_bundleName;
- var bundle = AssetBundle.LoadFromFile(bundlePath);
- if (bundle == null)
- {
- return;
- }
-
- m_rawImage.texture = bundle.LoadAsset<Texture>(m_iconName);
- bundle.Unload(false);
- }
- private void LoadFileBytes()
- {
- var bundlePath = Path.Combine(Application.streamingAssetsPath, m_bundleName);
- StartCoroutine(GetFileBytes(bundlePath));
- }
-
- IEnumerator GetFileBytes(string path)
- {
- var request = UnityWebRequest.Get(new System.Uri(path));
- yield return request.SendWebRequest();
- if (request.isNetworkError || request.isHttpError)
- {
- Debug.Log(request.error);
- yield break;
- }
-
- // 根据需求选择返回结果
- string text = request.downloadHandler.text;
- byte[] data = request.downloadHandler.data;
- }

如果需要下载并加载bundle使用的话使用UnityWebRequestAssetBundle
如果需要下载并加载Texture使用的话使用UnityWebRequestTexture
因为UnityWebReques的一些接口已经废弃,建议根据unity版本选择接口使用。
建议不要使WWW接口,因为该接口已经废弃了。