Example #1
0
            /// <summary>
            /// Loads a model from the given filename, file bytes or browser files.
            /// </summary>
            /// <param name="filename">Model filename.</param>
            /// <param name="fileBytes">Model file bytes.</param>
            /// <param name="browserFilesCount">Browser files count.</param>
            private void LoadInternal(string filename, byte[] fileBytes = null, int browserFilesCount = -1)
            {
                PreLoadSetup();
                var assetLoaderOptions = GetAssetLoaderOptions();

                if (!Async)
                {
                    using (var assetLoader = new AssetLoader())
                    {
                        assetLoader.OnMetadataProcessed += AssetLoader_OnMetadataProcessed;
                        try
                        {
#if !UNITY_EDITOR && UNITY_WEBGL
                            if (browserFilesCount >= 0)
                            {
                                _rootGameObject = assetLoader.LoadFromBrowserFilesWithTextures(browserFilesCount, assetLoaderOptions);
                            }
                            else
#endif
                            if (fileBytes != null && fileBytes.Length > 0)
                            {
                                _rootGameObject = assetLoader.LoadFromMemoryWithTextures(fileBytes, FileUtils.GetFileExtension(filename), assetLoaderOptions, _rootGameObject);
                            }
                            else if (!string.IsNullOrEmpty(filename))
                            {
                                _rootGameObject = assetLoader.LoadFromFileWithTextures(filename, assetLoaderOptions);
                            }
                            else
                            {
                                throw new Exception("File not selected");
                            }
                            CheckForValidModel(assetLoader);
                        }
                        catch (Exception exception)
                        {
                            HandleException(exception);
                        }
                    }
                    FullPostLoadSetup();
                }
                else
                {
                    using (var assetLoader = new AssetLoaderAsync())
                    {
                        assetLoader.OnMetadataProcessed += AssetLoader_OnMetadataProcessed;
                        try
                        {
#if !UNITY_EDITOR && UNITY_WEBGL
                            if (browserFilesCount >= 0)
                            {
                                assetLoader.LoadFromBrowserFilesWithTextures(browserFilesCount, assetLoaderOptions, null, delegate(GameObject loadedGameObject)
                                {
                                    CheckForValidModel(assetLoader);
                                    _rootGameObject = loadedGameObject;
                                    FullPostLoadSetup();
                                });
                            }
                            else
#endif
                            if (fileBytes != null && fileBytes.Length > 0)
                            {
                                assetLoader.LoadFromMemoryWithTextures(fileBytes, FileUtils.GetFileExtension(filename), assetLoaderOptions, null, delegate(GameObject loadedGameObject)
                                {
                                    CheckForValidModel(assetLoader);
                                    _rootGameObject = loadedGameObject;
                                    FullPostLoadSetup();
                                });
                            }
                            else if (!string.IsNullOrEmpty(filename))
                            {
                                assetLoader.LoadFromFileWithTextures(filename, assetLoaderOptions, null, delegate(GameObject loadedGameObject)
                                {
                                    CheckForValidModel(assetLoader);
                                    _rootGameObject = loadedGameObject;
                                    FullPostLoadSetup();
                                });
                            }
                            else
                            {
                                throw new Exception("File not selected");
                            }
                        }
                        catch (Exception exception)
                        {
                            HandleException(exception);
                        }
                    }
                }
            }
Example #2
0
            /// <summary>
            /// Loads a model from the given filename or given file bytes.
            /// </summary>
            /// <param name="filename">Model filename.</param>
            /// <param name="fileBytes">Model file bytes.</param>
            private void LoadInternal(string filename, byte[] fileBytes = null)
            {
                PreLoadSetup();
                var assetLoaderOptions = GetAssetLoaderOptions();

                if (!Async)
                {
                    using (var assetLoader = new AssetLoader())
                    {
                        assetLoader.OnMetadataProcessed += AssetLoader_OnMetadataProcessed;
                        try
                        {
#if (UNITY_WINRT && !UNITY_EDITOR_WIN)
                            var extension   = FileUtils.GetFileExtension(filename);
                            _rootGameObject = assetLoader.LoadFromMemoryWithTextures(fileBytes, extension, assetLoaderOptions, _rootGameObject);
#else
                            if (fileBytes != null && fileBytes.Length > 0)
                            {
                                var extension   = FileUtils.GetFileExtension(filename);
                                _rootGameObject = assetLoader.LoadFromMemoryWithTextures(fileBytes, extension, assetLoaderOptions, _rootGameObject);
                            }
                            else if (!string.IsNullOrEmpty(filename))
                            {
                                _rootGameObject = assetLoader.LoadFromFileWithTextures(filename, assetLoaderOptions);
                            }
                            else
                            {
                                throw new System.Exception("File not selected");
                            }
#endif
                        }
                        catch (System.Exception exception)
                        {
                            ErrorDialog.Instance.ShowDialog(exception.ToString());
                        }
                    }
                    if (_rootGameObject != null)
                    {
                        PostLoadSetup();
                    }
                }
                else
                {
                    using (var assetLoader = new AssetLoaderAsync())
                    {
                        assetLoader.OnMetadataProcessed += AssetLoader_OnMetadataProcessed;
                        try
                        {
                            if (fileBytes != null && fileBytes.Length > 0)
                            {
                                var extension = FileUtils.GetFileExtension(filename);
                                assetLoader.LoadFromMemoryWithTextures(fileBytes, extension, assetLoaderOptions, null, delegate(GameObject loadedGameObject)
                                {
                                    _rootGameObject = loadedGameObject;
                                    if (_rootGameObject != null)
                                    {
                                        PostLoadSetup();
                                    }
                                });
                            }
                            else if (!string.IsNullOrEmpty(filename))
                            {
                                assetLoader.LoadFromFileWithTextures(filename, assetLoaderOptions, null, delegate(GameObject loadedGameObject)
                                {
                                    _rootGameObject = loadedGameObject;
                                    if (_rootGameObject != null)
                                    {
                                        PostLoadSetup();
                                    }
                                });
                            }
                            else
                            {
                                throw new System.Exception("File not selected");
                            }
                        }
                        catch (System.Exception exception)
                        {
                            ErrorDialog.Instance.ShowDialog(exception.ToString());
                        }
                    }
                }
            }
            /// <summary>
            /// Loads a model from the given filename or given file bytes.
            /// </summary>
            /// <param name="filename">Model filename.</param>
            /// <param name="fileBytes">Model file bytes.</param>
            private void LoadInternal(string filename, byte[] fileBytes = null)
            {
                _loadingTimer.Reset();
                _loadingTimer.Start();
                PreLoadSetup();
                var assetLoaderOptions = GetAssetLoaderOptions();

                if (!Async)
                {
                    using (var assetLoader = new AssetLoader())
                    {
                        assetLoader.OnMetadataProcessed += AssetLoader_OnMetadataProcessed;
                        try
                        {
#if !UNITY_EDITOR && UNITY_WINRT && (NET_4_6 || NETFX_CORE || NET_STANDARD_2_0) && !ENABLE_IL2CPP && !ENABLE_MONO
                            var extension   = FileUtils.GetFileExtension(filename);
                            _rootGameObject = assetLoader.LoadFromMemoryWithTextures(fileBytes, extension, assetLoaderOptions, _rootGameObject);
#else
                            if (fileBytes != null && fileBytes.Length > 0)
                            {
                                var extension   = FileUtils.GetFileExtension(filename);
                                _rootGameObject = assetLoader.LoadFromMemoryWithTextures(fileBytes, extension, assetLoaderOptions, _rootGameObject);
                            }
                            else if (!string.IsNullOrEmpty(filename))
                            {
                                _rootGameObject = assetLoader.LoadFromFileWithTextures(filename, assetLoaderOptions);
                            }
                            else
                            {
                                throw new System.Exception("File not selected");
                            }
#endif
                        }
                        catch (Exception exception)
                        {
                            ErrorDialog.Instance.ShowDialog(exception.ToString());
                        }
                    }
                    if (_rootGameObject != null)
                    {
                        PostLoadSetup();
                        ShowLoadingTime();
                    }
                    else
                    {
                        HideLoadingTime();
                    }
                }
                else
                {
                    using (var assetLoader = new AssetLoaderAsync())
                    {
                        assetLoader.OnMetadataProcessed += AssetLoader_OnMetadataProcessed;
                        try
                        {
                            if (fileBytes != null && fileBytes.Length > 0)
                            {
                                var extension = FileUtils.GetFileExtension(filename);
                                assetLoader.LoadFromMemoryWithTextures(fileBytes, extension, assetLoaderOptions, null, delegate(GameObject loadedGameObject)
                                {
                                    _rootGameObject = loadedGameObject;
                                    if (_rootGameObject != null)
                                    {
                                        PostLoadSetup();
                                        ShowLoadingTime();
                                    }
                                    else
                                    {
                                        HideLoadingTime();
                                    }
                                });
                            }
                            else if (!string.IsNullOrEmpty(filename))
                            {
                                assetLoader.LoadFromFileWithTextures(filename, assetLoaderOptions, null, delegate(GameObject loadedGameObject)
                                {
                                    _rootGameObject = loadedGameObject;
                                    if (_rootGameObject != null)
                                    {
                                        PostLoadSetup();
                                        ShowLoadingTime();
                                    }
                                    else
                                    {
                                        HideLoadingTime();
                                    }
                                });
                            }
                            else
                            {
                                throw new Exception("File not selected");
                            }
                        }
                        catch (Exception exception)
                        {
                            HideLoadingTime();
                            ErrorDialog.Instance.ShowDialog(exception.ToString());
                        }
                    }
                }
            }