public IEnumerator GetAssetBundleAsync(string bundlePath, AssetBundleAsyncDelegate callback = null) { AssetBundleData abData = null; if (!abLoadDict.TryGetValue(bundlePath, out abData)) { ABDependDelegate dpCallback = (data) => { abData = data; }; yield return(LoadAssetBundleAsync(bundlePath, dpCallback)); } UpdateUsedTime(bundlePath); AssetBundle bundle = null; if (null != abData) { bundle = abData.mAssetBundle; } if (null != callback) { callback(true, bundle); } }
public IEnumerator LoadAsync <T>(string resPath, bool isScene, ResourceAsyncDelegate callback = null) where T : UnityEngine.Object { #if UNITY_EDITOR ResourceRecorder.Instance.RecordResource(resPath, typeof(T)); #endif if (IsTestMode) { if (null != callback) { callback(false, Resources.Load <T>(resPath)); } yield break; } System.Type resType = typeof(T); string abName = string.Empty; if (isScene) { abName = string.Format("assets/{0}.scene", resPath.ToLower()); } else { abName = string.Format("assets/resources/{0}{1}", resPath.ToLower(), GetAssetBundleName(resType)); } AssetBundleAsyncDelegate callbackFunc = (isBundle, assetbundle) => { if (null == assetbundle) { if (null != callback) { callback(false, isScene ? null : Resources.Load <T>(resPath)); } } else { if (assetbundle.isStreamedSceneAssetBundle) { if (null != callback) { callback(true, null); } } else if (null != callback) { string assetName = resPath.Substring(resPath.LastIndexOf("/") + 1).ToLower(); string[] allAssetNames = assetbundle.GetAllAssetNames(); for (int i = 0; i < allAssetNames.Length; i++) { if (allAssetNames[i].Contains(assetName)) { assetName = allAssetNames[i]; break; } } var o = assetbundle.LoadAsset(assetName); callback(true, o as T); } } }; yield return(mABDependsLoader.GetAssetBundleAsync(abName, callbackFunc)); }