2using System.Collections;
17 private UnityWebRequest _unityWebRequest;
22 private Action<AssetLoaderContext, float> _onProgress;
27 private AssetLoaderContext _assetLoaderContext;
41 public IEnumerator
DownloadAsset(UnityWebRequest unityWebRequest, Action<AssetLoaderContext> onLoad, Action<AssetLoaderContext> onMaterialsLoad, Action<AssetLoaderContext, float> onProgress, GameObject wrapperGameObject, Action<IContextualizedError> onError,
AssetLoaderOptions assetLoaderOptions,
object customContextData,
string fileExtension,
bool? isZipFile =
null)
43 _unityWebRequest = unityWebRequest;
44 _onProgress = onProgress;
45 yield
return unityWebRequest.SendWebRequest();
48 if (unityWebRequest.responseCode < 400)
50 var memoryStream =
new MemoryStream(_unityWebRequest.downloadHandler.data);
53 UnityWebRequest = _unityWebRequest,
54 CustomData = customContextData
56 var contentType = unityWebRequest.GetResponseHeader(
"Content-Type");
57 if (contentType !=
null && isZipFile ==
null)
59 isZipFile = contentType.Contains(
"application/zip") || contentType.Contains(
"application/x-zip-compressed") || contentType.Contains(
"multipart/x-zip");
61 if (!isZipFile.GetValueOrDefault() &&
string.IsNullOrWhiteSpace(fileExtension))
63 fileExtension = FileUtils.GetFileExtension(unityWebRequest.url);
65 if (isZipFile.GetValueOrDefault())
67 _assetLoaderContext = AssetLoaderZip.LoadModelFromZipStream(memoryStream, onLoad, onMaterialsLoad, delegate (AssetLoaderContext assetLoaderContext,
float progress) { onProgress?.Invoke(assetLoaderContext, 0.5f + progress * 0.5f); }, onError, wrapperGameObject, assetLoaderOptions, uriLoadCustomContextData, fileExtension);
71 _assetLoaderContext = AssetLoader.LoadModelFromStream(memoryStream,
null, fileExtension, onLoad, onMaterialsLoad, delegate (AssetLoaderContext assetLoaderContext,
float progress) { onProgress?.Invoke(assetLoaderContext, 0.5f + progress * 0.5f); }, onError, wrapperGameObject, assetLoaderOptions, uriLoadCustomContextData);
76 var exception =
new Exception($
"UnityWebRequest error:{unityWebRequest.error}, code:{unityWebRequest.responseCode}");
80 catch (Exception exception)
84 var contextualizedError = exception as IContextualizedError;
85 onError(contextualizedError ??
new ContextualizedError<AssetLoaderContext>(exception,
null));
98 _onProgress?.Invoke(_assetLoaderContext, _unityWebRequest.downloadProgress * 0.5F);
TriLibCore.AssetLoaderOptions AssetLoaderOptions
Represents a class used to download Models with Coroutines used by the Asset Downloader.
IEnumerator DownloadAsset(UnityWebRequest unityWebRequest, Action< AssetLoaderContext > onLoad, Action< AssetLoaderContext > onMaterialsLoad, Action< AssetLoaderContext, float > onProgress, GameObject wrapperGameObject, Action< IContextualizedError > onError, AssetLoaderOptions assetLoaderOptions, object customContextData, string fileExtension, bool? isZipFile=null)
Downloads the Model using the given Request and options.
Represents a class passed as the custom data to the Asset Loader Context when loading Models from URI...