示例#1
0
        /// <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="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, AssetLoaderOptions options = null, GameObject wrapperGameObject = null)
        {
            _unityWebRequest         = UnityWebRequest.Get(assetUri);
            _unityWebRequest.timeout = Timeout;
#if UNITY_2017_3_OR_NEWER
            yield return(_unityWebRequest.SendWebRequest());
#else
            yield return(_unityWebRequest.Send());
#endif
            if (string.IsNullOrEmpty(_unityWebRequest.error))
            {
                var data = _unityWebRequest.downloadHandler.data;
                try
                {
                    if (Async)
                    {
                        using (var assetLoaderAsync = new AssetLoaderAsync())
                        {
                            assetLoaderAsync.LoadFromMemoryWithTextures(data, assetExtension, options, wrapperGameObject,
                                                                        onAssetLoaded);
                        }
                    }
                    else
                    {
                        using (var assetLoader = new AssetLoader())
                        {
                            assetLoader.OnObjectLoaded += onAssetLoaded;
                            assetLoader.LoadFromMemoryWithTextures(data, assetExtension, options, wrapperGameObject);
                        }
                    }
                }
                catch (Exception exception)
                {
                    _error = exception.ToString();
                    if (onAssetLoaded != null)
                    {
                        onAssetLoaded(null);
                    }
                }
            }
            else
            {
                onAssetLoaded(null);
            }
            _unityWebRequest.Dispose();
            _unityWebRequest = null;
        }
示例#2
0
        /// <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="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>
        private IEnumerator DoDownloadAsset(string assetUri, string assetExtension, ObjectLoadedHandle onAssetLoaded,
                                            AssetLoaderOptions options = null, GameObject wrapperGameObject = null,
                                            AssimpInterop.ProgressCallback progressCallback = null)
        {
            _unityWebRequest         = UnityWebRequest.Get(assetUri);
            _unityWebRequest.timeout = Timeout;
            yield return(_unityWebRequest.SendWebRequest());

            if (string.IsNullOrEmpty(_unityWebRequest.error))
            {
                var data = _unityWebRequest.downloadHandler.data;
                try
                {
                    if (Async)
                    {
                        using (var assetLoaderAsync = new AssetLoaderAsync())
                        {
                            try
                            {
                                assetLoaderAsync.LoadFromMemoryWithTextures(data, assetExtension, options, wrapperGameObject, onAssetLoaded, null, null, null, progressCallback);
                            }
                            catch (Exception e)
                            {
                                _error = e.ToString();
                                if (onAssetLoaded != null)
                                {
                                    onAssetLoaded(null);
                                }
                            }
                        }
                    }
                    else
                    {
                        using (var assetLoader = new AssetLoader())
                        {
                            assetLoader.OnObjectLoaded += onAssetLoaded;
                            try
                            {
                                assetLoader.LoadFromMemoryWithTextures(data, assetExtension, options, wrapperGameObject, null, null, null, progressCallback);
                            }
                            catch (Exception e)
                            {
                                _error = e.ToString();
                                if (onAssetLoaded != null)
                                {
                                    onAssetLoaded(null);
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    _error = exception.ToString();
                    if (onAssetLoaded != null)
                    {
                        onAssetLoaded(null);
                    }
                }
            }
            else
            {
                _error = _unityWebRequest.error;
                if (onAssetLoaded != null)
                {
                    onAssetLoaded(null);
                }
            }
            _unityWebRequest.Dispose();
            _unityWebRequest = null;
        }