AB打包Day02
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadMan : MonoBehaviour {
// Use this for initialization
public string ABName;
string _abPath ;
string _manPath;
private List<AssetBundle> ManListAB;
void Start ()
{
ManListAB = new List<AssetBundle>();
//capsulepre
//www
_abPath = Application.streamingAssetsPath + "/Windows/";
_manPath = Application.streamingAssetsPath + "/Windows/Windows";
//不管啥 应该查找依赖关系
#region 加载依赖
AssetBundle _manAB = AssetBundle.LoadFromFile(_manPath);
//固定格式
AssetBundleManifest manifest = _manAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] dependencies = manifest.GetAllDependencies(ABName);
//加载依赖
if(dependencies.Length != 0)
foreach (string s in dependencies)
{
//挨个加载依赖关系
ManListAB.Add(LoadABByName(s)); // 存在内存中
}
#endregion
//依赖加载完毕 圆柱和立方体
AssetBundle _ab = AssetBundle.LoadFromFile(_abPath+ABName);
GameObject copyObj = _ab.LoadAsset<GameObject>("Capsule");
Instantiate(copyObj);
//释放ab依赖的内存
foreach (var v in ManListAB)
{
v.Unload(false);
}
_ab.Unload(false); // 不从场景里面剔除
//true 场景剔除
AssetBundle _ab01 = AssetBundle.LoadFromFile(_abPath+ABName); //_ab.Unload(false); 没有这句话会重复加载
GameObject copyObj01 = _ab01.LoadAsset<GameObject>("Capsule");
Instantiate(copyObj01,Vector3.one,Quaternion.identity);
}
// Update is called once per frame
void Update () {
}
private AssetBundle LoadABByName(string name)
{
return AssetBundle.LoadFromFile(_abPath + name);
}
}