public SDictionary <int, UnityEngine.Object> LoadAll(string bundleName, ELoadType loadType) { if (string.IsNullOrEmpty(bundleName)) { return(null); } LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(bundleName.GetHashCode()); if (loaded != null) { loaded.Count(); } else { loaded = LoadSyn(bundleName); } if (loaded != null) { loaded.mLoadType = loadType; if (loaded.mAssetBundle != null) { loaded.MapAssets(); ABManager.Instance.AfterLoad(loaded); } return(loaded.GetAllAssets()); } return(null); }
public Object Load(string bundleName, string assetName, ELoadType loadType) { if (string.IsNullOrEmpty(bundleName)) { return(null); } int nHashCode = bundleName.GetHashCode(); LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { loaded.Count(); } else { loaded = LoadSyn(bundleName); } if (loaded != null) { loaded.mLoadType = loadType; Object asset = null; if (loaded.mAssetBundle != null) { AssetBundle ab = loaded.mAssetBundle; if (string.IsNullOrEmpty(assetName)) { asset = ab.mainAsset != null ? ab.mainAsset : ab.LoadAsset(ab.GetAllAssetNames()[0]); if (asset != null) { loaded.SetMainAsset(asset); } } else { loaded.MapAssets(); asset = loaded.LoadAsset(assetName); } ABManager.Instance.AfterLoad(loaded); //Debug.Log("<color=yellow>assetName:" + assetName + "</color>"); } else { asset = loaded.LoadAsset(assetName); //Debug.Log("<color=red>assetName:"+ assetName + "</color>"); } return(asset); } return(null); }
public IEnumerator LoadAsync(string strFullName) { if (AssetBundleManifest == null || string.IsNullOrEmpty(strFullName)) { yield break; } InitAsync(); int nHashCode = strFullName.GetHashCode(); LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { loaded.Count(); yield break; } if (mLoadingReqs.Contains(nHashCode)) { yield break; } LoadFromType loadFromType = LoadFromType.LoadFromNone; string[] dependencies = null; if (AssetBundleManifest != null && AssetBundleHashSet.Contains(strFullName)) { loadFromType = LoadFromType.LoadFromDownLoad; dependencies = AssetBundleManifest.GetAllDependencies(strFullName); } else if (LocalABBundleManifest != null && LocalABBundleHashSet.Contains(strFullName)) { loadFromType = LoadFromType.LoadFromLocalAB; dependencies = LocalABBundleManifest.GetAllDependencies(strFullName); } int nLength = dependencies.Length; if (nLength > 0) { DependencsLoader dependCallBack = mDependItemPool.GetObject(); if (dependCallBack != null) { dependCallBack.Reset(); dependCallBack.mLength = nLength; } for (int i = 0; i < nLength; ++i) { ResourceManager.Instance.StartCoroutine(LoadBundleByWWW(dependencies[i], dependCallBack, loadFromType)); } while (!dependCallBack.AllDone) { yield return(null); } mDependItemPool.RemoveObject(dependCallBack); } yield return(ResourceManager.Instance.StartCoroutine(LoadBundleByWWW(strFullName, null, loadFromType))); loaded = ABManager.Instance.GetLoadedBundle(nHashCode); if (loaded != null) { if (nLength > 0) { loaded.AddDpendences(dependencies); } loaded.MapAssets(); ABManager.Instance.AfterLoad(loaded); } yield return(null); }
public LoadedAssetBundle LoadSyn(string strFullName, UpdateProgress updateFunc = null, bool bSend = false) { LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(strFullName.GetHashCode()); if (loaded != null) { loaded.Count(); return(loaded); } AssetManageInfo info = AssetManageConfigManager.Instance.GetInfo(strFullName); //资源是从DownLoad包里还是StreamAsset的包里读取的 LoadFromType loadFromType = LoadFromType.LoadFromNone; string[] dependencies = null; if (AssetBundleManifest != null && AssetBundleHashSet.Contains(strFullName)) {//是否在下载的包里 loadFromType = LoadFromType.LoadFromDownLoad; dependencies = AssetBundleManifest.GetAllDependencies(strFullName); } else if (LocalABBundleManifest != null && LocalABBundleHashSet.Contains(strFullName)) {//下载的包里找不到就到跟包的目录里寻找一遍看是否有依赖 loadFromType = LoadFromType.LoadFromLocalAB; dependencies = LocalABBundleManifest.GetAllDependencies(strFullName); } //只要不是LoadFromNone,说明这个资源是有身份证的,并非来路不明 if (loadFromType != LoadFromType.LoadFromNone) { int nCnt = 1; if (dependencies != null) { nCnt += dependencies.Length; for (int i = 0; i < dependencies.Length; ++i) { LoadBundleByFileStream(dependencies[i], getLoadFromType(dependencies[i]), AssetEncryptMode.None); if (updateFunc != null) { updateFunc((float)(i + 1) / nCnt, bSend); } } } //Debug.Log("<color=red> LoadSyn: " + strFullName + "</color>"); loaded = LoadBundleByFileStream(strFullName, loadFromType, info.encryption); if (loaded != null) { if (dependencies != null && dependencies.Length > 0) { loaded.AddDpendences(dependencies); } if (info.loadType != ELoadType.Music && info.loadType != ELoadType.Scene) { loaded.MapAssets(); ABManager.Instance.AfterLoad(loaded); } if (updateFunc != null) { updateFunc(1.0f, bSend); } } return(loaded); } else { Debug.Log("<color=red>资源:" + strFullName + "来路不明,在bundle表里不存在。</color>"); return(null); } }