赞
踩
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.Networking;
-
- public class LoadAssetBundles : MonoBehaviour {
-
- IEnumerator Start ()
- {
- string rootPath = Application.streamingAssetsPath;
-
- string path = rootPath+ "/AssetBundles/cubewall.unity3d";
-
- //AssetBundle ab1 = AssetBundle.LoadFromFile("AssetBundles/scenes/share.unity3d");
-
-
- //第一种从内存异步加载 IEnumerator
- AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path));
- yield return request;
- AssetBundle ab = request.assetBundle;
-
- AssetBundle assetBundleManifest = AssetBundle.LoadFromFile(rootPath+"/AssetBundles/AssetBundles");
- AssetBundleManifest manifest = assetBundleManifest.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
-
- //foreach (string name in manifest.GetAllAssetBundles())
- //{
- // Debug.Log(name);
- //}
-
- string[] dependencies = manifest.GetAllDependencies("cubewall.unity3d");
-
- foreach (string str in dependencies)
- {
- print(str);
- AssetBundle.LoadFromFile(rootPath+"/AssetBundles/" + str);
- }
-
- //实例化资源
- GameObject wallPrefab = ab.LoadAsset<GameObject>("cubewall");
- Instantiate(wallPrefab);
-
-
- //AssetBundle.UnloadAllAssetBundles(true);
-
- }
-
- }
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.Networking;
-
- public class LoadAssetBundles : MonoBehaviour {
-
- IEnumerator Start ()
- {
- string rootPath = Application.streamingAssetsPath;
-
- string path = rootPath+ "/AssetBundles/cubewall.unity3d";
-
- AssetBundle ab1 = AssetBundle.LoadFromFile("AssetBundles/scenes/share.unity3d");
-
- //第二种从本地异步加载 IEnumerator
- AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(path);
- yield return request;
- AssetBundle ab = request.assetBundle;
-
- //AssetBundle ab = AssetBundle.LoadFromFile("AssetBundles/scenes/cubewall.unity3d");
-
- AssetBundle assetBundleManifest = AssetBundle.LoadFromFile(rootPath+"/AssetBundles/AssetBundles");
- AssetBundleManifest manifest = assetBundleManifest.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
-
- //foreach (string name in manifest.GetAllAssetBundles())
- //{
- // Debug.Log(name);
- //}
-
- string[] dependencies = manifest.GetAllDependencies("cubewall.unity3d");
-
- foreach (string str in dependencies)
- {
- print(str);
- AssetBundle.LoadFromFile(rootPath+"/AssetBundles/" + str);
- }
-
- //实例化资源
- GameObject wallPrefab = ab.LoadAsset<GameObject>("cubewall");
- Instantiate(wallPrefab);
-
-
- //AssetBundle.UnloadAllAssetBundles(true);
-
- }
-
- }
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.Networking;
-
- public class LoadAssetBundles : MonoBehaviour {
-
- IEnumerator Start ()
- {
- string rootPath = Application.streamingAssetsPath;
-
- string path = rootPath+ "/AssetBundles/cubewall.unity3d";
-
- AssetBundle ab1 = AssetBundle.LoadFromFile("AssetBundles/scenes/share.unity3d");
-
- //第三种使用www来加载
- while (!Caching.ready)
- {
- yield return null;
- }
- WWW www = WWW.LoadFromCacheOrDownload(@"file://E:\UnityProjects\Unity5.4\AssetBundleProjects\Assets\StreamingAssets\AssetBundles\AssetBundles\cubewall.unity3d", 1);
- //WWW www = WWW.LoadFromCacheOrDownload(@"http://192.168.1.102/AssetBundles\cubewall.unity3d", 1);
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- Debug.Log(www.error);
- yield break;
- }
-
- AssetBundle ab = www.assetBundle;
-
- AssetBundle assetBundleManifest = AssetBundle.LoadFromFile(rootPath+"/AssetBundles/AssetBundles");
- AssetBundleManifest manifest = assetBundleManifest.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
-
- //foreach (string name in manifest.GetAllAssetBundles())
- //{
- // Debug.Log(name);
- //}
-
- string[] dependencies = manifest.GetAllDependencies("cubewall.unity3d");
-
- foreach (string str in dependencies)
- {
- print(str);
- AssetBundle.LoadFromFile(rootPath+"/AssetBundles/" + str);
- }
-
- //实例化资源
- GameObject wallPrefab = ab.LoadAsset<GameObject>("cubewall");
- Instantiate(wallPrefab);
-
-
- //AssetBundle.UnloadAllAssetBundles(true);
-
- }
-
- }
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.Networking;
-
- public class LoadAssetBundles : MonoBehaviour {
-
- IEnumerator Start ()
- {
- string rootPath = Application.streamingAssetsPath;
-
- string path = rootPath+ "/AssetBundles/cubewall.unity3d";
-
- AssetBundle ab1 = AssetBundle.LoadFromFile("AssetBundles/scenes/share.unity3d");
-
- //第四种使用UnityWebRequest
- string url = @"file://E:\UnityProjects\Unity5.4\AssetBundleProjects\Assets\StreamingAssets\AssetBundles\cubewall.unity3d";
- //string url = @"http://192.168.1.102/AssetBundles\cubewall.unity3d";
-
- UnityWebRequest request = UnityWebRequest.GetAssetBundle(url);
- yield return request.Send();
-
- //AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
- AssetBundle ab = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
-
- AssetBundle assetBundleManifest = AssetBundle.LoadFromFile(rootPath+"/AssetBundles/AssetBundles");
- AssetBundleManifest manifest = assetBundleManifest.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
-
- //foreach (string name in manifest.GetAllAssetBundles())
- //{
- // Debug.Log(name);
- //}
-
- string[] dependencies = manifest.GetAllDependencies("cubewall.unity3d");
-
- foreach (string str in dependencies)
- {
- print(str);
- AssetBundle.LoadFromFile(rootPath+"/AssetBundles/" + str);
- }
-
- //实例化资源
- GameObject wallPrefab = ab.LoadAsset<GameObject>("cubewall");
- Instantiate(wallPrefab);
-
-
- //AssetBundle.UnloadAllAssetBundles(true);
-
- }
-
- }
- AssetBundle assetBundle = AssetBundle.LoadFromFile(manifestFilePath);
- AssetBundleManifest manifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
- string[] dependencies = manifest.GetAllDependencies("assetBundle"); //Pass the name of the bundle you want the dependencies for.
- foreach (string name in manifest.GetAllAssetBundles())
- {
- Debug.Log(name);
- }
- foreach (string dependency in dependencies)
- {
- AssetBundle.LoadFromFile(Path.Combine(assetBundlePath, dependency));
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。