예제 #1
0
        /// <summary>
        /// Launches a picker which allows the user to choose multiple files to open
        /// </summary>
        /// <param name="commitButtonText">Text for the ok button</param>
        /// <param name="viewMode">Display files as either a list or thumbnails</param>
        /// <param name="suggestedStartLocation">Suggested initial directory</param>
        /// <param name="filters">File extension filters - specify an empty array to allow all</param>
        /// <param name="response">Contains the chosen files or null if nothing was selected</param>
        public static void PickMultipleFiles(string commitButtonText, WSAPickerViewMode viewMode, WSAPickerLocationId suggestedStartLocation, string[] filters,
                                             Action <IEnumerable <WSAStorageFile> > response)
        {
#if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0)
            UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
            {
                FileOpenPicker openPicker         = new FileOpenPicker();
                openPicker.SuggestedStartLocation = MapWSAPickerLocationIdToPickerLocationId(suggestedStartLocation);
                openPicker.ViewMode         = viewMode == WSAPickerViewMode.List ? PickerViewMode.List : PickerViewMode.Thumbnail;
                openPicker.CommitButtonText = commitButtonText;

                if (filters != null && filters.Length > 0)
                {
                    foreach (string filter in filters)
                    {
                        openPicker.FileTypeFilter.Add(filter);
                    }
                }
                else
                {
                    openPicker.FileTypeFilter.Add("*");
                }

                IReadOnlyList <StorageFile> files = await openPicker.PickMultipleFilesAsync();

                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    if (response != null)
                    {
                        response(files != null && files.Any() ? files.Select(x => MapStorageFileToWSAStorageFile(x)) : null);
                    }
                }, true);
            }, false);
#endif
        }
        /// <summary>
        /// Launches a picker which allows the user to choose a folder
        /// </summary>
        /// <param name="commitButtonText">Text for the ok button</param>
        /// <param name="viewMode">Display folders as either a list or thumbnails</param>
        /// <param name="suggestedStartLocation">Suggested initial directory</param>
        /// <param name="filters">File extension filters - specify an empty array to allow all</param>
        /// <param name="response">Contains the chosen folder or null if nothing was selected</param>
        public static void PickSingleFolder(string commitButtonText, WSAPickerViewMode viewMode, WSAPickerLocationId suggestedStartLocation, string[] filters, Action <WSAStorageFolder> response)
        {
#if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0)
            UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
            {
                FolderPicker folderPicker           = new FolderPicker();
                folderPicker.SuggestedStartLocation = MapWSAPickerLocationIdToPickerLocationId(suggestedStartLocation);
                folderPicker.ViewMode         = viewMode == WSAPickerViewMode.List ? PickerViewMode.List : PickerViewMode.Thumbnail;
                folderPicker.CommitButtonText = commitButtonText;

                if (filters != null && filters.Length > 0)
                {
                    foreach (string filter in filters)
                    {
                        folderPicker.FileTypeFilter.Add(filter);
                    }
                }
                else
                {
                    folderPicker.FileTypeFilter.Add("*");
                }

                StorageFolder folder = await folderPicker.PickSingleFolderAsync();

                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    if (response != null)
                    {
                        response(folder != null ? MapStorageFolderToWSAStorageFolder(folder) : null);
                    }
                }, true);
            }, false);
#endif
        }
예제 #3
0
        /// <summary>
        /// Launches a picker which allows the user to choose a file to open
        /// </summary>
        /// <param name="commitButtonText">Text for the ok button</param>
        /// <param name="viewMode">Display files as either a list or thumbnails</param>
        /// <param name="suggestedStartLocation">Suggested initial directory</param>
        /// <param name="filters">File extension filters - specify an empty array to allow all</param>
        /// <param name="response">Contains the chosen file or null if nothing was selected</param>
        public static void PickSingleFile(string commitButtonText, WSAPickerViewMode viewMode, WSAPickerLocationId suggestedStartLocation, string[] filters, Action <WSAStorageFile> response)
        {
#if NETFX_CORE
            UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
            {
                FileOpenPicker openPicker         = new FileOpenPicker();
                openPicker.SuggestedStartLocation = MapWSAPickerLocationIdToPickerLocationId(suggestedStartLocation);
                openPicker.ViewMode         = viewMode == WSAPickerViewMode.List ? PickerViewMode.List : PickerViewMode.Thumbnail;
                openPicker.CommitButtonText = commitButtonText;

                if (filters != null && filters.Length > 0)
                {
                    foreach (string filter in filters)
                    {
                        openPicker.FileTypeFilter.Add(filter);
                    }
                }
                else
                {
                    openPicker.FileTypeFilter.Add("*");
                }

                StorageFile file = await openPicker.PickSingleFileAsync();

                UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                {
                    if (response != null)
                    {
                        response(MapStorageFileToWSAStorageFile(file));
                    }
                }, true);
            }, false);
#endif
        }