/// <summary> /// Shows the progress on screen, if ShowProgress is set to <c>true</c>. /// </summary> //protected void OnGUI() //{ // if (!ShowProgress || !HasStarted || IsDone) // { // return; // } // if (_centeredStyle == null) // { // _centeredStyle = GUI.skin.GetStyle("Label"); // _centeredStyle.alignment = TextAnchor.UpperCenter; // } // var centeredRect = new Rect(Screen.width / 2f - 100f, Screen.height / 2f - 25f, 200f, 50f); // GUI.Label(centeredRect, string.Format("Downloaded {0:P2}", Progress), _centeredStyle); //} /// <summary> /// Downloads an asset. /// </summary> /// <returns><c>true</c>, if asset was downloaded, <c>false</c> otherwise.</returns> /// <param name="assetURI">Asset URI.</param> /// <param name="assetExtension">Asset extension.</param> /// <param name="onAssetLoaded">On asset loaded event.</param> /// <param name="onTexturePreLoad">On texture pre load event.</param> /// <param name="options">Asset loading options.</param> /// <param name="wrapperGameObject">Wrapper <see cref="UnityEngine.GameObject"/> to load the asset into.</param> public bool DownloadAsset(string assetURI, string assetExtension, ObjectLoadedHandle onAssetLoaded = null, TexturePreLoadHandle onTexturePreLoad = null, AssetLoaderOptions options = null, GameObject wrapperGameObject = null) { if (HasStarted && !IsDone) { return(false); } AssetURI = assetURI; AssetExtension = assetExtension; WrapperGameObject = wrapperGameObject; DownloadEvents.DownloadStart(); StartCoroutine(DoDownloadAsset(assetURI, assetExtension, onAssetLoaded, options, wrapperGameObject)); return(true); }
/// <summary> /// Downloads an asset. /// </summary> /// <returns><c>true</c>, if asset was downloaded, <c>false</c> otherwise.</returns> /// <param name="assetURI">Asset URI.</param> /// <param name="assetExtension">Asset extension.</param> /// <param name="onAssetLoaded">On asset loaded event.</param> /// <param name="onTexturePreLoad">On texture pre load event.</param> /// <param name="options">Asset loading options.</param> /// <param name="wrapperGameObject">Wrapper <see cref="UnityEngine.GameObject"/> to load the asset into.</param> /// <param name="progressCallback">Callback used to retrieve file loading percentage.</param> public bool DownloadAsset(string assetURI, string assetExtension, ObjectLoadedHandle onAssetLoaded = null, TexturePreLoadHandle onTexturePreLoad = null, AssetLoaderOptions options = null, GameObject wrapperGameObject = null, AssimpInterop.ProgressCallback progressCallback = null) { if (HasStarted && !IsDone) { return(false); } AssetURI = assetURI; AssetExtension = assetExtension; WrapperGameObject = wrapperGameObject; StartCoroutine(DoDownloadAsset(assetURI, assetExtension, onAssetLoaded, options, wrapperGameObject, progressCallback)); return(true); }
/// <summary> /// Internal asset download coroutine. /// </summary> /// <returns>The coroutine IEnumerator.</returns> /// <param name="assetURI">Asset URI.</param> /// <param name="assetExtension">Asset extension.</param> /// <param name="onAssetLoaded">On asset loaded event.</param> /// <param name="onTexturePreLoad">On texture pre load event.</param> /// <param name="options">Asset loading options.</param> /// <param name="wrapperGameObject">Wrapper <see cref="UnityEngine.GameObject"/> to load the asset into.</param> private IEnumerator DoDownloadAsset(string assetURI, string assetExtension, ObjectLoadedHandle onAssetLoaded, TexturePreLoadHandle onTexturePreLoad = null, AssetLoaderOptions options = null, GameObject wrapperGameObject = null) { _unityWebRequest = UnityWebRequest.Get(assetURI); yield return(_unityWebRequest.Send()); if (string.IsNullOrEmpty(_unityWebRequest.error)) { var data = _unityWebRequest.downloadHandler.data; using (var assetLoader = new AssetLoader()) { assetLoader.LoadFromMemoryWithTextures(data, assetExtension, onAssetLoaded, out _error, onTexturePreLoad, options, wrapperGameObject); } } _unityWebRequest.Dispose(); _unityWebRequest = null; }