Beispiel #1
0
        void OnGUI_Spreadsheet_Local_ImportExport(eLocalSpreadsheeet CurrentExtension, string File)
        {
            GUI.enabled = (CurrentExtension != eLocalSpreadsheeet.NONE);

            GUILayout.BeginHorizontal();
            GUILayout.Space(10);

            GUI.backgroundColor = Color.Lerp(Color.gray, Color.white, 0.5f);
            eSpreadsheetUpdateMode Mode = SynchronizationButtons("Import");

            if (Mode != eSpreadsheetUpdateMode.None)
            {
                Import_Local(File, CurrentExtension, Mode);
            }

            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.Lerp(Color.gray, Color.white, 0.5f);
            Mode = SynchronizationButtons("Export", true);
            if (Mode != eSpreadsheetUpdateMode.None)
            {
                Export_Local(File, CurrentExtension, Mode);
            }

            GUILayout.Space(10);
            GUILayout.EndHorizontal();

            GUI.enabled = true;
        }
        void Export_Local(string File, eLocalSpreadsheeet CurrentExtension, eSpreadsheetUpdateMode UpdateMode)
        {
            try
            {
                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
                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)
            {
                ShowError("Unable to export file\nCheck it is not READ-ONLY and that\nits not opened in an external viewer");
            }
        }
Beispiel #3
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);
            }
        }
        void OnGUI_Spreadsheet_Local_ImportExport(eLocalSpreadsheeet CurrentExtension, string File)
        {
            GUI.enabled = (CurrentExtension != eLocalSpreadsheeet.NONE);

            GUILayout.BeginHorizontal();
            GUILayout.Space(10);

            GUI.backgroundColor = Color.Lerp(Color.gray, Color.white, 0.5f);
            eSpreadsheetUpdateMode Mode = SynchronizationButtons("Import");

            if (Mode != eSpreadsheetUpdateMode.None)
            {
                Import_Local(File, CurrentExtension, Mode);
            }

            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.Lerp(Color.gray, Color.white, 0.5f);
            Mode = SynchronizationButtons("Export", true);
            if (Mode != eSpreadsheetUpdateMode.None)
            {
                Export_Local(File, CurrentExtension, Mode);
            }

            GUILayout.Space(10);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUIUtility.labelWidth += 10;
            EditorGUILayout.PropertyField(mProp_Spreadsheet_SpecializationAsRows, new GUIContent("Show Specializations as Rows", "true: Make each specialization a separate row (e.g. Term[VR]..., Term[Touch]....\nfalse: Merge specializations into same cell separated by [i2s_XXX]"));
            EditorGUIUtility.labelWidth -= 10;
            GUILayout.EndHorizontal();


            GUI.enabled = true;
        }
Beispiel #5
0
        void OnGUI_Spreadsheet_Local()
        {
            GUILayout.Space(10);
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("File:", GUILayout.ExpandWidth(false));

            mProp_Spreadsheet_LocalFileName.stringValue = EditorGUILayout.TextField(mProp_Spreadsheet_LocalFileName.stringValue);

            /*if (GUILayout.Button("...", "toolbarbutton", GUILayout.ExpandWidth(false)))
             * {
             *      string sFileName = mProp_Spreadsheet_LocalFileName.stringValue;
             *
             *      string sPath = string.Empty;
             *      try {
             *      sPath = System.IO.Path.GetDirectoryName(sFileName);
             *      }
             *      catch( System.Exception e){}
             *
             *      if (string.IsNullOrEmpty(sPath))
             *              sPath = Application.dataPath + "/";
             *
             *      sFileName = System.IO.Path.GetFileName(sFileName);
             *      if (string.IsNullOrEmpty(sFileName))
             *              sFileName = "Localization.csv";
             *
             *      string FullFileName = EditorUtility.SaveFilePanel("Select CSV File", sPath, sFileName, "csv");
             *      //string FullFileName = EditorUtility.OpenFilePanel("Select CSV,  XLS or XLSX File", sFileName, "csv;*.xls;*.xlsx");
             *
             *      if (!string.IsNullOrEmpty(FullFileName))
             *      {
             *              Prop_LocalFileName.stringValue = TryMakingPathRelativeToProject(FullFileName);
             *      }
             * }*/
            GUILayout.EndHorizontal();

            //--[ Find current extension ]---------------
            eLocalSpreadsheeet CurrentExtension = eLocalSpreadsheeet.NONE;

            //string FileNameLower = Prop_LocalFileName.stringValue.ToLower();
            /*if (FileNameLower.EndsWith(".csv"))  */ CurrentExtension = eLocalSpreadsheeet.CSV;

            /*if (FileNameLower.EndsWith(".xls"))  CurrentExtension = eLocalSpreadsheeet.XLS;
             *  if (FileNameLower.EndsWith(".xlsx")) CurrentExtension = eLocalSpreadsheeet.XLSX;*/

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            switch (CurrentExtension)
            {
            case eLocalSpreadsheeet.NONE:
            case eLocalSpreadsheeet.CSV:
            {
                string FileTypesDesc = "Select or Drag any file of the following types:\n\n";
                FileTypesDesc += "*.csv  (Comma Separated Values)\n";
                FileTypesDesc += "*.txt  (CSV file renamed as txt)\n";
                //FileTypesDesc+= "\n*.xls  (Excel 97-2003)";
                //FileTypesDesc+= "\n*.xlsx (Excel Open XML format)";
                EditorGUILayout.HelpBox(FileTypesDesc, MessageType.None);
            }
            break;

            case eLocalSpreadsheeet.XLS: EditorGUILayout.HelpBox("Excel 97-2003", MessageType.None); break;

            case eLocalSpreadsheeet.XLSX: EditorGUILayout.HelpBox("Excel Open XML format", MessageType.None); break;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            //--[ Allow Dragging files ]-----------------
            if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && IsValidDraggedLoadSpreadsheet())
            {
                if (Event.current.type == EventType.DragUpdated)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                }

                if (Event.current.type == EventType.DragPerform)
                {
                    mProp_Spreadsheet_LocalFileName.stringValue = TryMakingPathRelativeToProject(DragAndDrop.paths[0]);
                    DragAndDrop.AcceptDrag();
                    Event.current.Use();
                }
            }

            GUILayout.Space(10);

            OnGUI_Spreadsheet_Local_ImportExport(CurrentExtension, mProp_Spreadsheet_LocalFileName.stringValue);

            //if (Application.platform == RuntimePlatform.OSXEditor)

            //-- CSV Separator ----------------
            GUI.changed = false;
            var CSV_Separator = mProp_Spreadsheet_LocalCSVSeparator.stringValue;

            if (string.IsNullOrEmpty(CSV_Separator))
            {
                CSV_Separator = ",";
            }

            GUILayout.Space(10);
            GUILayout.BeginHorizontal("Box");
            GUILayout.Label("Separator:");
            GUILayout.FlexibleSpace();

            if (GUILayout.Toggle(CSV_Separator == ",", "Comma(,)") && CSV_Separator != ",")
            {
                CSV_Separator = ",";
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Toggle(CSV_Separator == ";", "Semicolon(;)") && CSV_Separator != ";")
            {
                CSV_Separator = ";";
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Toggle(CSV_Separator == "\t", "TAB(\\t)") && CSV_Separator != "\t")
            {
                CSV_Separator = "\t";
            }

            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                mProp_Spreadsheet_LocalCSVSeparator.stringValue = CSV_Separator;
            }

            GUILayout.Space(10);
            EditorGUILayout.HelpBox("On some Mac OS, there is a Unity Bug that makes the IDE crash when selecting a CSV file in the Open/Save File Dialog.\nJust by clicking the file, unity tries to preview the content and crashes.\n\nIf any of your the team members use Mac, its adviced to import/export the CSV Files with TXT extension.", MessageType.Warning);
            GUILayout.Space(10);

            OnGUI_ShowMsg();
        }