private void OnGUI() { if (GUILayout.Button("Cube")) { string abPath = string.Format("file:///{0}/AssetBundle/3dobj", Application.streamingAssetsPath); _abLoader.GetAssetAsync <GameObject>(abPath, "Cube", (obj) => { if (obj != null) { GameObject.Instantiate(obj); } }, _ => { Debug.Log($"Cube Progress {_}"); }); } if (GUILayout.Button("Sphere")) { string abPath = string.Format("file:///{0}/AssetBundle/3dobj", Application.streamingAssetsPath); _abLoader.GetAssetAsync <GameObject>(abPath, "Sphere", (obj) => { if (obj != null) { GameObject.Instantiate(obj); } }, _ => { Debug.Log($"Sphere Progress {_}"); }); } if (GUILayout.Button("Image")) { string abPath = string.Format("file:///{0}/AssetBundle/image", Application.streamingAssetsPath); _abLoader.GetAssetAsync <GameObject>(abPath, "Image", (obj) => { if (obj != null) { GameObject.Instantiate(obj, canvas.transform); } }, _ => { Debug.Log($"Image Progress {_}"); }); } }
public void LoadManifestAssetBundleAsync(string abPath, Action callback = null, Action <float> progressCallback = null) { SetupAbRoot(abPath); _loader.GetAssetAsync <AssetBundleManifest>(abPath, "AssetBundleManifest", (manifest) => { if (manifest != null) { _coreManifest = manifest; _manifestLoaded = true; callback?.Invoke(); } }, progressCallback); }
public void GetAssetAsync <T>(string abPath, string assetName, Action <T> callback, Action <float> progressCallback = null) where T : Object { T asset = GetAssetFromCache <T>(abPath, assetName); if (asset == null) { _abLoader?.GetAssetAsync <T>(abPath, assetName, (t) => { SetAssetToCache(abPath, assetName, t); callback?.Invoke(t); }, progressCallback); } else { progressCallback?.Invoke(1); callback?.Invoke(asset); } }
/// <summary> /// 异步获取资源 /// </summary> /// <typeparam name="T">资源类型</typeparam> /// <param name="abPath">资源ab包路径</param> /// <param name="assetName">资源名</param> /// <param name="callback">资源回调</param> /// <param name="progressCallback">进度回调</param> public void GetAssetAsync <T>(string abPath, string assetName, Action <T> callback, Action <float> progressCallback = null) where T : UnityEngine.Object { _loader?.GetAssetAsync <T>(abPath, assetName, callback, progressCallback); }