public override bool LoadSync() { if (!CheckLoadAble()) { return(false); } if (string.IsNullOrEmpty(AssetBundleName)) { return(false); } Object obj = null; if (AssetBundlePathHelper.SimulationMode && !string.Equals(mAssetName, "assetbundlemanifest")) { var resSearchKeys = ResSearchKeys.Allocate(AssetBundleName, null, typeof(AssetBundle)); var abR = ResMgr.Instance.GetRes <AssetBundleRes>(resSearchKeys); resSearchKeys.Recycle2Cache(); var assetPaths = AssetBundlePathHelper.GetAssetPathsFromAssetBundleAndAssetName(abR.AssetName, mAssetName); if (assetPaths.Length == 0) { Log.E("Failed Load Asset:" + mAssetName); OnResLoadFaild(); return(false); } HoldDependRes(); State = ResState.Loading; if (AssetType != null) { obj = AssetBundlePathHelper.LoadAssetAtPath(assetPaths[0], AssetType); } else { obj = AssetBundlePathHelper.LoadAssetAtPath <Object>(assetPaths[0]); } } else { var resSearchKeys = ResSearchKeys.Allocate(AssetBundleName, null, typeof(AssetBundle)); var abR = ResMgr.Instance.GetRes <AssetBundleRes>(resSearchKeys); resSearchKeys.Recycle2Cache(); if (abR == null || !abR.AssetBundle) { Log.E("Failed to Load Asset, Not Find AssetBundleImage:" + AssetBundleName); return(false); } HoldDependRes(); State = ResState.Loading; if (AssetType != null) { obj = abR.AssetBundle.LoadAsset(mAssetName, AssetType); } else { obj = abR.AssetBundle.LoadAsset(mAssetName); } } UnHoldDependRes(); if (obj == null) { Log.E("Failed Load Asset:" + mAssetName + ":" + AssetType + ":" + AssetBundleName); OnResLoadFaild(); return(false); } mAsset = obj; State = ResState.Ready; return(true); }
public override IEnumerator DoLoadAsync(System.Action finishCallback) { if (RefCount <= 0) { OnResLoadFaild(); finishCallback(); yield break; } //Object obj = null; var resSearchKeys = ResSearchKeys.Allocate(AssetBundleName, null, typeof(AssetBundle)); var abR = ResMgr.Instance.GetRes <AssetBundleRes>(resSearchKeys); resSearchKeys.Recycle2Cache(); if (AssetBundlePathHelper.SimulationMode && !string.Equals(mAssetName, "assetbundlemanifest")) { var assetPaths = AssetBundlePathHelper.GetAssetPathsFromAssetBundleAndAssetName(abR.AssetName, mAssetName); if (assetPaths.Length == 0) { Log.E("Failed Load Asset:" + mAssetName); OnResLoadFaild(); finishCallback(); yield break; } //确保加载过程中依赖资源不被释放:目前只有AssetRes需要处理该情况 HoldDependRes(); State = ResState.Loading; // 模拟等一帧 yield return(new WaitForEndOfFrame()); UnHoldDependRes(); if (AssetType != null) { mAsset = AssetBundlePathHelper.LoadAssetAtPath(assetPaths[0], AssetType); } else { mAsset = AssetBundlePathHelper.LoadAssetAtPath <Object>(assetPaths[0]); } } else { if (abR == null || abR.AssetBundle == null) { Log.E("Failed to Load Asset, Not Find AssetBundleImage:" + AssetBundleName); OnResLoadFaild(); finishCallback(); yield break; } HoldDependRes(); State = ResState.Loading; AssetBundleRequest abQ = null; if (AssetType != null) { abQ = abR.AssetBundle.LoadAssetAsync(mAssetName, AssetType); mAssetBundleRequest = abQ; yield return(abQ); } else { abQ = abR.AssetBundle.LoadAssetAsync(mAssetName); mAssetBundleRequest = abQ; yield return(abQ); } mAssetBundleRequest = null; UnHoldDependRes(); if (!abQ.isDone) { Log.E("Failed Load Asset:" + mAssetName); OnResLoadFaild(); finishCallback(); yield break; } mAsset = abQ.asset; } State = ResState.Ready; finishCallback(); }