using UnityEditor;
using System.IO;
public class CreatAssetBundles {
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
string dir = "AssetBundles";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
BuildPipeline.BuildAssetBundles(dir, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows64);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.Networking;
public class LoadABExample : MonoBehaviour
{
IEnumerator Start()
{
string path = @"file:///E:\UnityProject\AssetBundleProject\AssetBundles\scene\cubewall.unity3d";
//string path = @"http://localhost/AssetBundles/scene/cubewall.unity3d";
//while (Caching.ready == false)
//{
// yield return null;
//}
//WWW www = WWW.LoadFromCacheOrDownload(path, 1);
//yield return www;
//if (!string.IsNullOrEmpty(www.error))
//{
// print(www.error);
//}
using (UnityWebRequest request = UnityWebRequest.GetAssetBundle(path))
{
yield return request.SendWebRequest();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
//AssetBundle ab = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
AssetBundle manifestAB = AssetBundle.LoadFromFile("AssetBundles/AssetBundles");
AssetBundleManifest manifest = manifestAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] strs = manifest.GetAllDependencies("scene/cubewall.unity3d");
foreach (string name in strs)
{
print(name);
AssetBundle.LoadFromFile("AssetBundles/" + name);
}
GameObject wallPrefab = ab.LoadAsset<GameObject>("CubeWall");
Instantiate(wallPrefab);
ab.Unload(false);
}
}
}