コード例 #1
0
    public static Permission ExportMultipleFiles(string[] filePaths, FilesExportedCallback callback = null)
    {
        if (filePaths == null || filePaths.Length == 0)
        {
            throw new ArgumentException("Parameter 'filePaths' is null or empty!");
        }

        Permission result = RequestPermission(false);

        if (result == Permission.Granted && !IsFilePickerBusy())
        {
            if (CanExportMultipleFiles())
            {
#if !UNITY_EDITOR && UNITY_ANDROID
                AJC.CallStatic("ExportFiles", Context, new FPResultCallbackAndroid(null, null, callback), filePaths, filePaths.Length);
#elif !UNITY_EDITOR && UNITY_IOS
                FPResultCallbackiOS.Initialize(null, null, callback);
                _NativeFilePicker_ExportFiles(filePaths, filePaths.Length);
#endif
            }
            else if (callback != null)
            {
                callback(false);
            }
        }

        return(result);
    }
コード例 #2
0
ファイル: NativeFilePicker.cs プロジェクト: Not-Pace/gARphics
    public static Permission ExportMultipleFiles(string[] filePaths, FilesExportedCallback callback = null)
    {
        if (filePaths == null || filePaths.Length == 0)
        {
            throw new ArgumentException("Parameter 'filePaths' is null or empty!");
        }

        Permission result = RequestPermission(false);

        if (result == Permission.Granted && !IsFilePickerBusy())
        {
            if (CanExportMultipleFiles())
            {
#if UNITY_EDITOR
                string destination = UnityEditor.EditorUtility.OpenFolderPanel("Select destination", Path.GetDirectoryName(filePaths[0]), "");
                if (string.IsNullOrEmpty(destination))
                {
                    if (callback != null)
                    {
                        callback(false);
                    }
                }
                else
                {
                    try
                    {
                        for (int i = 0; i < filePaths.Length; i++)
                        {
                            File.Copy(filePaths[i], Path.Combine(destination, Path.GetFileName(filePaths[i])), true);
                        }

                        if (callback != null)
                        {
                            callback(true);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);

                        if (callback != null)
                        {
                            callback(false);
                        }
                    }
                }
#elif UNITY_ANDROID
                AJC.CallStatic("ExportFiles", Context, new FPResultCallbackAndroid(null, null, callback), filePaths, filePaths.Length);
#elif UNITY_IOS
                FPResultCallbackiOS.Initialize(null, null, callback);
                _NativeFilePicker_ExportFiles(filePaths, filePaths.Length);
#endif
            }
            else if (callback != null)
            {
                callback(false);
            }
        }

        return(result);
    }
コード例 #3
0
ファイル: NativeFilePicker.cs プロジェクト: Not-Pace/gARphics
    public static Permission ExportFile(string filePath, FilesExportedCallback callback = null)
    {
        if (string.IsNullOrEmpty(filePath))
        {
            throw new ArgumentException("Parameter 'filePath' is null or empty!");
        }

        Permission result = RequestPermission(false);

        if (result == Permission.Granted && !IsFilePickerBusy())
        {
            if (CanExportFiles())
            {
#if UNITY_EDITOR
                string extension = Path.GetExtension(filePath);
                if (extension == null)
                {
                    extension = "";
                }
                else if (extension.IndexOf('.') == 0)
                {
                    extension = extension.Substring(1);
                }

                string destination = UnityEditor.EditorUtility.SaveFilePanel("Select destination", Path.GetDirectoryName(filePath), Path.GetFileName(filePath), extension);
                if (string.IsNullOrEmpty(destination))
                {
                    if (callback != null)
                    {
                        callback(false);
                    }
                }
                else
                {
                    try
                    {
                        File.Copy(filePath, destination, true);

                        if (callback != null)
                        {
                            callback(true);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);

                        if (callback != null)
                        {
                            callback(false);
                        }
                    }
                }
#elif UNITY_ANDROID
                AJC.CallStatic("ExportFiles", Context, new FPResultCallbackAndroid(null, null, callback), new string[1] {
                    filePath
                }, 1);
#elif UNITY_IOS
                FPResultCallbackiOS.Initialize(null, null, callback);
                _NativeFilePicker_ExportFiles(new string[1] {
                    filePath
                }, 1);
#endif
            }
            else if (callback != null)
            {
                callback(false);
            }
        }

        return(result);
    }