/// <summary> /// load asset bundle from file /// </summary> /// <param name="path"></param> /// <param name="tag"></param> /// <param name="cacheLoadedAsset"></param> /// <returns>AssetBundleReference retainted.ref count add one after load.</returns> public AssetBundleReference LoadAssetBundleSync(string path, int tag, bool cacheLoadedAsset = true) { if (string.IsNullOrEmpty(path)) { return(null); } AssetBundleReference abr = null; if (m_AssetBundles.ContainsKey(path)) { #if ASSETMANAGER_LOG_ON Debug.LogFormat("[AssetManage]LoadAssetBundleSync bundle is loaded {0},{1}", path, Time.frameCount); #endif abr = m_AssetBundles[path]; //refresh abr.AddTag(tag); if (cacheLoadedAsset) { abr.Cache(); } } else { if (m_LoadingAssetBundleLoaders.ContainsKey(path)) { Debug.LogErrorFormat("[AssetManage]LoadAssetBundleSync async loader is active {0},{1}", path, Time.frameCount); //TODO Stop async return(null); } else { #if ASSETMANAGER_LOG_ON Debug.LogFormat("[AssetManage]LoadAssetBundleSync create new loader {0},{1}", path, Time.frameCount); #endif AssetBundleSyncLoader loader = m_LoaderManager.CreateAssetBundleSyncLoader(path); if (loader != null) { loader.state = Loader.State.Inited; if (loader.cacheLoadedAsset == false && cacheLoadedAsset) { loader.cacheLoadedAsset = true; } loader.Start(); abr = loader.result; //must retain . will be destory by loader clean abr.Retain(); OnAssetBundleBeforeLoaded(loader); OnAssetBundleAfterLoaded(loader); } } } return(abr); }
public AssetBundleSyncLoader CreateAssetBundleSyncLoader(string path) { AssetBundleSyncLoader loader = null; #if !UNITY_EDITOR || ASSET_BUNDLE_LOADER AssetBundleInfo info = null; info = m_AssetManager.infoManager.FindAssetBundleInfo(path); if (info != null) { loader = new AssetBundleSyncLoader(); loader.info = info; loader.assetManager = m_AssetManager; } else { Debug.LogErrorFormat("[AssetManage]Can't find asset bundle info {0}", path); } #endif return(loader); }