Tanoda
AssetDownloader.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using TriLibCore.General;
4using UnityEngine;
5using UnityEngine.Networking;
6
7namespace TriLibCore
8{
10 public class AssetDownloader
11 {
14 {
16 Get,
18 Post,
20 Put,
22 Delete,
24 Head
25 }
26
33 public static UnityWebRequest CreateWebRequest(string uri, HttpRequestMethod httpRequestMethod = HttpRequestMethod.Get, string data = null, int timeout = 2000)
34 {
35 UnityWebRequest unityWebRequest;
36 switch (httpRequestMethod)
37 {
38 case HttpRequestMethod.Post:
39 unityWebRequest = UnityWebRequest.Post(uri, data);
40 break;
41 case HttpRequestMethod.Put:
42 unityWebRequest = UnityWebRequest.Put(uri, data);
43 break;
44 case HttpRequestMethod.Delete:
45 unityWebRequest = UnityWebRequest.Delete($"{uri}?{data}");
46 break;
47 case HttpRequestMethod.Head:
48 unityWebRequest = UnityWebRequest.Head($"{uri}?{data}");
49 break;
50 default:
51 unityWebRequest = UnityWebRequest.Get($"{uri}?{data}");
52 break;
53 }
54 unityWebRequest.timeout = timeout;
55 return unityWebRequest;
56 }
57
70 public static Coroutine LoadModelFromUri(UnityWebRequest unityWebRequest, Action<AssetLoaderContext> onLoad, Action<AssetLoaderContext> onMaterialsLoad, Action<AssetLoaderContext, float> onProgress, Action<IContextualizedError> onError = null, GameObject wrapperGameObject = null, AssetLoaderOptions assetLoaderOptions = null, object customContextData = null, string fileExtension = null, bool? isZipFile = null)
71 {
72 var assetDownloader = new GameObject("Asset Downloader").AddComponent<AssetDownloaderBehaviour>();
73 return assetDownloader.StartCoroutine(assetDownloader.DownloadAsset(unityWebRequest, onLoad, onMaterialsLoad, onProgress, wrapperGameObject, onError, assetLoaderOptions, customContextData, fileExtension, isZipFile));
74 }
75 }
76}
TriLibCore.AssetLoaderOptions AssetLoaderOptions
Definition: TriLibLoader.cs:9
Represents a class used to download Models with Coroutines used by the Asset Downloader.
Represents a class to download and load Models.
HttpRequestMethod
Represents an HTTP Request method.
static Coroutine LoadModelFromUri(UnityWebRequest unityWebRequest, Action< AssetLoaderContext > onLoad, Action< AssetLoaderContext > onMaterialsLoad, Action< AssetLoaderContext, float > onProgress, Action< IContextualizedError > onError=null, GameObject wrapperGameObject=null, AssetLoaderOptions assetLoaderOptions=null, object customContextData=null, string fileExtension=null, bool? isZipFile=null)
Loads a Model from the given URI Asynchronously (Accepts zip files).
static UnityWebRequest CreateWebRequest(string uri, HttpRequestMethod httpRequestMethod=HttpRequestMethod.Get, string data=null, int timeout=2000)
Creates a Unity Web Request from the given parameters.