public void LoadAsset(string path, Action <GameObject> fn) { string bundleName = path.ToLower(); string assetName = path + ".prefab"; ABPrefabInfo abInfo = null; _cachePrefabs.TryGetValue(bundleName, out abInfo); if (abInfo != null) { GameObject prefab = abInfo.GetPrefab(); if (prefab) { //Prefab已被加载 fn(prefab); } else { //Prefab正在加载 abInfo.AddListener(fn); } } else { //第一加载Prefab abInfo = new ABPrefabInfo(fn); _cachePrefabs.Add(bundleName, abInfo); AssetBundleLoader.Instance().LoadAsset(bundleName, assetName, (assetObj) => { abInfo.LoadedPrefab(assetObj as GameObject); }); } }
//获得Prefab public GameObject GetPrefab(string path) { ABPrefabInfo obj = null; _cachePrefabs.TryGetValue(path.ToLower(), out obj); return(obj.GetPrefab()); }