void Export_Local(string File, eLocalSpreadsheeet CurrentExtension, eSpreadsheetUpdateMode UpdateMode)
        {
            try
            {
                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
                LocalizationEditor.ClearErrors();

                string sPath = string.Empty;
                if (!System.IO.Path.IsPathRooted(File))
                {
                    File = string.Concat(Application.dataPath, "/", File);
                }

                try {
                    sPath = System.IO.Path.GetDirectoryName(File);
                }
                catch (System.Exception) {}

                if (string.IsNullOrEmpty(sPath))
                {
                    sPath = Application.dataPath + "/";
                }

                File = System.IO.Path.GetFileName(File);
                if (string.IsNullOrEmpty(File))
                {
                    File = "Localization.csv";
                }

                if (Application.platform == RuntimePlatform.OSXEditor)
                {
                    File = EditorUtility.SaveFilePanel("Select a CSV file renamed as TXT", sPath, File, "txt");
                }
                else
                {
                    File = EditorUtility.SaveFilePanel("Select a CSV or TXT file", sPath, File, "csv;*.txt");
                }
                if (!string.IsNullOrEmpty(File))
                {
                    mLanguageSource.Spreadsheet_LocalFileName = TryMakingPathRelativeToProject(File);

                    char Separator = mProp_Spreadsheet_LocalCSVSeparator.stringValue.Length > 0 ? mProp_Spreadsheet_LocalCSVSeparator.stringValue[0] : ',';
                    var  encoding  = System.Text.Encoding.GetEncoding(mProp_Spreadsheet_LocalCSVEncoding.stringValue);
                    if (encoding == null)
                    {
                        encoding = System.Text.Encoding.UTF8;
                    }

                    switch (CurrentExtension)
                    {
                    case eLocalSpreadsheeet.CSV: Export_CSV(File, UpdateMode, Separator, encoding); break;
                    }
                }
            }
            catch (System.Exception)
            {
                LocalizationEditor.ShowError("Unable to export file\nCheck it is not READ-ONLY and that\nits not opened in an external viewer");
            }
        }
Exemplo n.º 2
0
        void Import_Local(string File, eLocalSpreadsheeet CurrentExtension, eSpreadsheetUpdateMode UpdateMode)
        {
            try
            {
                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
                LocalizationEditor.ClearErrors();

                if (string.IsNullOrEmpty(File))
                {
                    File = Application.dataPath + "/Localization.csv";
                }
                else
                if (!System.IO.Path.IsPathRooted(File))
                {
                    File = string.Concat(Application.dataPath, "/", File);
                }

                // On Mac there is an issue with previewing CSV files, so its forced to only TXT
                if (Application.platform == RuntimePlatform.OSXEditor)
                {
                    File = EditorUtility.OpenFilePanel("Select a CSV file renamed as TXT", File, "txt");
                }
                else
                {
                    File = EditorUtility.OpenFilePanel("Select a CSV file or a CSV file renamed as TXT", File, "csv;*.txt");
                }
                //File = EditorUtility.OpenFilePanel("Select CSV,  XLS or XLSX File", File, "csv;*.xls;*.xlsx");
                if (!string.IsNullOrEmpty(File))
                {
                    mLanguageSource.Spreadsheet_LocalFileName = TryMakingPathRelativeToProject(File);
                    switch (CurrentExtension)
                    {
                    case eLocalSpreadsheeet.CSV: Import_CSV(File, UpdateMode); break;
                    }
                    ParseTerms(true);
                    UnityEditor.EditorUtility.SetDirty(target);
                    AssetDatabase.SaveAssets();
                }
            }
            catch (System.Exception ex)
            {
                LocalizationEditor.ShowError("Unable to import file");
                Debug.LogError(ex.Message);
            }
        }