Ejemplo n.º 1
0
        /// <summary>
        /// Setups the Avatar Loader instance reference and fills the available files list.
        /// </summary>
        protected void Start()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (FreeLookCamPrefab == null || ThirdPersonControllerPrefab == null)
                {
                    if (EditorUtility.DisplayDialog(DialogTitle, "This sample is not configured.\nDo you want to configure it now?", "Yes", "No"))
                    {
                        SetupAvatarLoaderSample();
                    }
                }
            }
#endif
            _avatarLoader = FindObjectOfType <AvatarLoader>();
            if (_avatarLoader == null)
            {
#if TRILIB_OUTPUT_MESSAGES
                Debug.LogError("Could not find any Avatar Loader script instance.");
#endif
                return;
            }
#if UNITY_EDITOR
            var modelsPath = Path.Combine(Path.GetFullPath("./Assets/TriLib/TriLibExtras/Samples"), ModelsDirectory);
#else
            var modelsPath = Path.Combine(Path.GetFullPath("."), ModelsDirectory);
#endif
            var supportedExtensions = AssetLoaderBase.GetSupportedFileExtensions();
            _files      = Directory.GetFiles(modelsPath, "*.*").Where(x => supportedExtensions.Contains(Path.GetExtension(x).ToLower())).ToArray();
            _windowRect = new Rect(20, 20, 240, Screen.height - 40);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Handles "Load local asset button" click event and tries to load an asset at chosen path.
            /// </summary>
            private void LoadLocalAssetButtonClick()
            {
                var fileOpenDialog = FileOpenDialog.Instance;

                fileOpenDialog.Title  = "Please select a File";
                fileOpenDialog.Filter = AssetLoaderBase.GetSupportedFileExtensions() + "*.zip;";
#if (UNITY_WINRT && !UNITY_EDITOR_WIN)
                fileOpenDialog.ShowFileOpenDialog(delegate(byte[] fileBytes, string filename)
                {
                    LoadInternal(filename, fileBytes);
#else
                fileOpenDialog.ShowFileOpenDialog(delegate(string filename)
                {
#endif
                    LoadInternal(filename, null);
                }
                                                  );
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Setups the Avatar Loader instance reference and fills the available files list.
        /// </summary>
        protected void Start()
        {
            _avatarLoader = FindObjectOfType <AvatarLoader>();
            if (_avatarLoader == null)
            {
                Debug.LogError("Could not find any Avatar Loader script instance.");
                return;
            }
#if UNITY_EDITOR
            var modelsPath = string.Format("{0}/Samples/{1}", TriLibProjectUtils.FindPathRelativeToProject("TriLibExtras", "t:DefaultAsset TriLibExtras"), ModelsDirectory);
#else
            var modelsPath = Path.Combine(Path.GetFullPath("."), ModelsDirectory);
#endif
            var supportedExtensions = AssetLoaderBase.GetSupportedFileExtensions();
            _files               = Directory.GetFiles(modelsPath, "*.*").Where(x => supportedExtensions.Contains("*" + FileUtils.GetFileExtension(x) + ";")).ToArray();
            _windowRect          = new Rect(20, 20, 240, Screen.height - 40);
            InformationText.text = string.Format(InformationText.text, ModelsDirectory, modelsPath);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Handles "Load local asset button" click event and tries to load an asset at chosen path.
            /// </summary>
            private void LoadLocalAssetButtonClick()
            {
                var fileOpenDialog = FileOpenDialog.Instance;

                fileOpenDialog.Title  = "Please select a File";
                fileOpenDialog.Filter = AssetLoaderBase.GetSupportedFileExtensions() + "*.zip;";
#if !UNITY_EDITOR && UNITY_WINRT && (NET_4_6 || NETFX_CORE || NET_STANDARD_2_0) && !ENABLE_IL2CPP && !ENABLE_MONO
                fileOpenDialog.ShowFileOpenDialog(delegate(byte[] fileBytes, string filename)
                {
                    LoadInternal(filename, fileBytes);
#else
                fileOpenDialog.ShowFileOpenDialog(delegate(string filename)
                {
                    LoadInternal(filename);
#endif
                }
                                                  );
            }
Ejemplo n.º 5
0
            /// <summary>
            /// Handles "Load local asset button" click event and tries to load an asset at chosen path.
            /// </summary>
            private void LoadLocalAssetButtonClick()
            {
#if !UNITY_EDITOR && UNITY_WEBGL
                ErrorDialog.Instance.ShowDialog("Please drag and drop your model files into the browser window.");
#else
                var fileOpenDialog = FileOpenDialog.Instance;
                fileOpenDialog.Title  = "Please select a File";
                fileOpenDialog.Filter = AssetLoaderBase.GetSupportedFileExtensions() + ";*.zip;";
#if !UNITY_EDITOR && UNITY_WINRT && (NET_4_6 || NETFX_CORE || NET_STANDARD_2_0)
                fileOpenDialog.ShowFileOpenDialog(delegate(byte[] fileBytes, string filename)
                {
                    LoadInternal(filename, fileBytes);
#else
                fileOpenDialog.ShowFileOpenDialog(delegate(string filename)
                {
                    LoadInternal(filename);
#endif
                }
                                                  );
#endif
            }
Ejemplo n.º 6
0
        //Searches inside a path and returns the first path of an asset loadable by TriLib
        private string GetReadableAssetPath(string path)
        {
            var supportedExtensions = AssetLoaderBase.GetSupportedFileExtensions();

            foreach (var file in Directory.GetFiles(path))
            {
                var fileExtension = FileUtils.GetFileExtension(file);
                if (supportedExtensions.Contains(fileExtension))
                {
                    return(file);
                }
            }
            foreach (var directory in Directory.GetDirectories(path))
            {
                var assetPath = GetReadableAssetPath(directory);
                if (assetPath != null)
                {
                    return(assetPath);
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
            /// <summary>
            /// Handles "Load local asset button" click event and tries to load an asset at chosen path.
            /// </summary>
            private void LoadLocalAssetButtonClick()
            {
                var fileOpenDialog = FileOpenDialog.Instance;

                fileOpenDialog.Title  = "Please select a File";
                fileOpenDialog.Filter = AssetLoaderBase.GetSupportedFileExtensions();
#if (UNITY_WINRT && !UNITY_EDITOR_WIN)
                fileOpenDialog.ShowFileOpenDialog(delegate(byte[] fileBytes, string filename)
#else
                fileOpenDialog.ShowFileOpenDialog(delegate(string filename)
#endif
                {
                    PreLoadSetup();
                    var assetLoaderOptions = GetAssetLoaderOptions();
                    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
                            _rootGameObject = assetLoader.LoadFromFile(filename, assetLoaderOptions);
#endif
                        }
                        catch (System.Exception exception)
                        {
                            ErrorDialog.Instance.ShowDialog(exception.ToString());
                        }
                    }
                    if (_rootGameObject != null)
                    {
                        PostLoadSetup();
                    }
                }
                                                  );
            }
            /// <summary>
            /// Stores a reference to all assets supported by TriLib located at "persistentDataPath".
            /// </summary>
            private void Start()
            {
                var filter = AssetLoaderBase.GetSupportedFileExtensions();

                _files = Directory.GetFiles(Application.persistentDataPath, "*.*").Where(x => filter.Contains("*" + FileUtils.GetFileExtension(x) + ";")).ToArray();
            }