public IEnumerator LoadAssetAsync(string assetPath, OnLoadAssetFinished onLoadAssetFinished) { #if UNITY_EDITOR if (AssetBundleUtility.SimulateAssetBundleInEditor) { UnityEngine.Object asset = AssetDatabase.LoadMainAssetAtPath(Path.Combine(AssetBundleUtility.AssetBundleResourcesPath, assetPath) + ".prefab"); onLoadAssetFinished(asset); yield break; } #endif string assetBundleName = assetPath + AssetBundleUtility.AssetBundleExtension; yield return(StartCoroutine(LoadAssetBundleWithDependenciesAsync(assetBundleName))); AssetBundle bundle = mLoadedAssetBundles[assetBundleName].mAssetBundle; string assetName = Path.GetFileName(assetPath); AssetBundleRequest assetRequest = bundle.LoadAssetAsync(assetName); yield return(assetRequest); if (assetRequest.asset == null) { Debug.LogErrorFormat("Load Asset Failed: {0}", assetName); yield break; } bundle.Unload(false); onLoadAssetFinished(assetRequest.asset); }
public IEnumerator LoadAssetAsync(string assetPath, OnLoadAssetFinished onLoadAssetFinished) { #if UNITY_EDITOR if (AssetBundleUtility.SimulateAssetBundleInEditor) { UnityEngine.Object asset = AssetDatabase.LoadMainAssetAtPath(Path.Combine(AssetBundleUtility.AssetBundleResourcesPath, assetPath) + ".prefab"); onLoadAssetFinished(asset); yield break; } #endif string assetBundleName = assetPath + AssetBundleUtility.AssetBundleExtension; yield return StartCoroutine(LoadAssetBundleWithDependenciesAsync(assetBundleName)); AssetBundle bundle = mLoadedAssetBundles[assetBundleName].mAssetBundle; string assetName = Path.GetFileName(assetPath); AssetBundleRequest assetRequest = bundle.LoadAssetAsync(assetName); yield return assetRequest; if (assetRequest.asset == null) { Debug.LogErrorFormat("Load Asset Failed: {0}", assetName); yield break; } bundle.Unload(false); onLoadAssetFinished(assetRequest.asset); }