首先在Editor文件夹下创建快捷打包的方式
[MenuItem(“AssetBuiled/Build”)]
static void EditorWindow()
{
string path = “AssetBundle”;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
}
如果需要在安卓端的话 修改下 方法中的BuildTarget
把预制体和材质球设置为下图格式 然后点击窗口下的AssetBuiled中的Build**
这是加载后的效果 一个cube和对应的材质球
预制体和对应材质球设置 把他们放置在同一个文件夹CC下
blog.csdnimg.cn/20181119173144714.)这里插入图片描述](https://img-blog.csdnimg.cn/20181119173025865.?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2x5YjE5OTQwNTI2,size_16,color_FFFFFF,t_70)
void Start()
{
//1.从本地加载
AssetBundle assetBundle = AssetBundle.LoadFromFile(“AssetBundle/cc/cube”);
GameObject cube = assetBundle.LoadAsset(“cube”);
Instantiate(cube);
AssetBundle AB = AssetBundle.LoadFromFile(“AssetBundle/AssetBundle”);
AssetBundleManifest manifset = AB.LoadAsset(“AssetBundleManifest”);
string[] manifsetAB = manifset.GetAllDependencies(“cc/cube”);
foreach (var item in manifsetAB)
{
//获取到cube所有的依赖项后给加载出来
AssetBundle.LoadFromFile(“AssetBundle/” + item);
}
}加粗样式
IEnumerator Start()
{
#region 从内存加载
AssetBundleCreateRequest asset = AssetBundle.LoadFromFileAsync(@“C:\Users\Administrator\Desktop\斗地主\单机版\assetBuild\AssetBundle\cc\cube”);
yield return asset;
AssetBundle assetBundle = asset.assetBundle;
GameObject cube = assetBundle.LoadAsset(“Cube”);
Instantiate(cube);
AssetBundle AB = AssetBundle.LoadFromFile(“AssetBundle/AssetBundle”);
AssetBundleManifest manifset = AB.LoadAsset(“AssetBundleManifest”);
string[] manifsetAB = manifset.GetAllDependencies(“cc/cube”);
foreach (var item in manifsetAB)
{
//获取到cube所有的依赖项后给加载出来
AssetBundle.LoadFromFile(“AssetBundle/” + item);
}
#endregion
#region 用WWW类加载
//WWW a = new WWW(@“http://192.168.201.35/AssetBundle/cc/cube”);
//yield return a;
//AssetBundle asset = a.assetBundle;
//GameObject cube = asset.LoadAsset(“Cube”);
//Instantiate(cube);
//AssetBundle ab = AssetBundle.LoadFromFile(“AssetBundle/AssetBundle”);
//AssetBundleManifest bundleManifest = ab.LoadAsset(“AssetBundleManifest”);
//string[] all = bundleManifest.GetAllDependencies(“cc/cube”);
//foreach (var item in all)
//{
// AssetBundle.LoadFromFile(“AssetBundle/” + item);
//}
#endregion
#region 从服务器加载
//UnityWebRequest request = UnityWebRequest.GetAssetBundle(@“http://192.168.201.35/AssetBundle/cc/cube”);
//yield return request.Send();
//AssetBundle asset = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
//GameObject cube = asset.LoadAsset(“cube”);
//Instantiate(cube);
//AssetBundle AB = AssetBundle.LoadFromFile(“AssetBundle/AssetBundle”);
//AssetBundleManifest manifset = AB.LoadAsset(“AssetBundleManifest”);
//string[] manifsetAB = manifset.GetAllDependencies(“cc/cube”);
//foreach (var item in manifsetAB)
//{
// //获取到cube所有的依赖项后给加载出来
// AssetBundle.LoadFromFile(“AssetBundle/” + item);
//}
#endregion
}
目前不太懂服务器的相关知识,后两种只是一个小的尝试