示例#1
0
 /// <summary>
 /// Draws our custom inspector.
 /// </summary>
 public override void OnInspectorGUI()
 {
     table = target as LocalizedTextTable;
     if (table == null)
     {
         return;
     }
     EditorGUILayout.HelpBox("Localized Text Tables have been superceded by Text Tables. To save the contents of this Localized Text Table as a Text Table, click the 'Save As Text Table...' button below.", MessageType.Info);
     if (GUILayout.Button("Save As Text Table..."))
     {
         SaveAsTextTable();
     }
     else
     {
         DrawLanguages();
         EditorWindowTools.DrawHorizontalLine();
         if (showSearchBar)
         {
             DrawSearchBar();
             EditorWindowTools.DrawHorizontalLine();
         }
         DrawFields();
         if (GUI.changed)
         {
             EditorUtility.SetDirty(table);
         }
     }
 }
 /// <summary>
 /// Draws our custom inspector.
 /// </summary>
 public override void OnInspectorGUI()
 {
     table = target as LocalizedTextTable;
     if (table == null) return;
     DrawLanguages();
     EditorWindowTools.DrawHorizontalLine();
     DrawFields();
     if (GUI.changed) EditorUtility.SetDirty(table);
 }
        private static LocalizedTextTable CreateLocalizedTextTableInstance()
        {
            LocalizedTextTable table = ScriptableObject.CreateInstance <LocalizedTextTable>();

            table.languages = new List <string> {
                "Default"
            };
            return(table);
        }
 public void LocalizeText()
 {
     if (!started)
     {
         return;
     }
     if (string.IsNullOrEmpty(PixelCrushers.DialogueSystem.Localization.Language))
     {
         return;
     }
     if (text == null)
     {
         text = GetComponent <Text>();
     }
     if (string.IsNullOrEmpty(fieldName))
     {
         fieldName = (text != null) ? text.text : string.Empty;
     }
     if (localizedTextTable == null)
     {
         localizedTextTable = DialogueManager.DisplaySettings.localizationSettings.localizedText;
     }
     if (text == null)
     {
         if (DialogueDebug.LogWarnings)
         {
             Debug.LogWarning(DialogueDebug.Prefix + ": LocalizeUILabel didn't find a Text component on " + name + ".", this);
         }
     }
     else if (localizedTextTable == null)
     {
         if (DialogueDebug.LogWarnings)
         {
             Debug.LogWarning(DialogueDebug.Prefix + ": No localized text table is assigned to " + name + " or the Dialogue Manager.", this);
         }
     }
     else if (!localizedTextTable.ContainsField(fieldName))
     {
         if (DialogueDebug.LogWarnings)
         {
             Debug.LogWarning(DialogueDebug.Prefix + ": Localized text table '" + localizedTextTable.name + "' does not have a field: " + fieldName, this);
         }
     }
     else if (!HasCurrentLanguage())
     {
         if (DialogueDebug.LogWarnings)
         {
             Debug.LogWarning(DialogueDebug.Prefix + "Localized text table '" + localizedTextTable + "' does not have a language '" + PixelCrushers.DialogueSystem.Localization.Language + "'", this);
         }
     }
     else
     {
         text.text = localizedTextTable[fieldName];
     }
 }
 /// <summary>
 /// Draws our custom inspector.
 /// </summary>
 public override void OnInspectorGUI()
 {
     table = target as LocalizedTextTable;
     if (table == null)
     {
         return;
     }
     DrawLanguages();
     EditorWindowTools.DrawHorizontalLine();
     DrawFields();
     if (GUI.changed)
     {
         EditorUtility.SetDirty(table);
     }
 }
		public void LocalizeText() {
			if (!started) return;
			if (string.IsNullOrEmpty(PixelCrushers.DialogueSystem.Localization.Language)) return;
			if (text == null) text = GetComponent<UnityEngine.UI.Text>();
			if (string.IsNullOrEmpty(fieldName)) fieldName = (text != null) ? text.text : string.Empty;
			if (localizedTextTable == null) {
				localizedTextTable = DialogueManager.DisplaySettings.localizationSettings.localizedText;
			}
			if (text == null) {
				if (DialogueDebug.LogWarnings) Debug.LogWarning(DialogueDebug.Prefix + ": LocalizeUILabel didn't find a Text component on " + name + ".", this);
			} else if (localizedTextTable == null) {
				if (DialogueDebug.LogWarnings) Debug.LogWarning(DialogueDebug.Prefix + ": No localized text table is assigned to " + name + " or the Dialogue Manager.", this);
			} else if (!localizedTextTable.ContainsField(fieldName)) {
				if (DialogueDebug.LogWarnings) Debug.LogWarning(DialogueDebug.Prefix + ": Localized text table '" + localizedTextTable.name + "' does not have a field: " + fieldName, this);
			} else if (!HasCurrentLanguage()) {
				if (DialogueDebug.LogWarnings) Debug.LogWarning(DialogueDebug.Prefix + "Localized text table '" + localizedTextTable + "' does not have a language '" + PixelCrushers.DialogueSystem.Localization.Language + "'", this);
			} else {
				text.text = localizedTextTable[fieldName];
			}
		}
示例#7
0
        public virtual void LocalizeText()
        {
            if (!started)
            {
                return;
            }

            // Skip if no language set:
            if (string.IsNullOrEmpty(PixelCrushers.DialogueSystem.Localization.Language))
            {
                return;
            }
            if (localizedTextTable == null)
            {
                localizedTextTable = DialogueManager.DisplaySettings.localizationSettings.localizedText;
                if (localizedTextTable == null)
                {
                    if (DialogueDebug.LogWarnings)
                    {
                        Debug.LogWarning(DialogueDebug.Prefix + ": No localized text table is assigned to " + name + " or the Dialogue Manager.", this);
                    }
                    return;
                }
            }

            if (!HasCurrentLanguage())
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarning(DialogueDebug.Prefix + "Localized text table '" + localizedTextTable + "' does not have a language '" + PixelCrushers.DialogueSystem.Localization.Language + "'", this);
                }
                return;
            }

            // Make sure we have a Text or Dropdown:
            if (text == null && dropdown == null)
            {
                text = GetComponent <UnityEngine.UI.Text>();
#if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1)
                dropdown = GetComponent <UnityEngine.UI.Dropdown>();
#endif
                if (text == null && dropdown == null)
                {
                    if (DialogueDebug.LogWarnings)
                    {
                        Debug.LogWarning(DialogueDebug.Prefix + ": LocalizeUIText didn't find a Text or Dropdown component on " + name + ".", this);
                    }
                    return;
                }
            }

            // Get the original values to use as field lookups:
            if (string.IsNullOrEmpty(fieldName))
            {
                fieldName = (text != null) ? text.text : string.Empty;
            }
#if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1)
            if ((fieldNames.Count == 0) && (dropdown != null))
            {
                dropdown.options.ForEach(opt => fieldNames.Add(opt.text));
            }
#endif
            // Localize Text:
            if (text != null)
            {
                if (!localizedTextTable.ContainsField(fieldName))
                {
                    if (DialogueDebug.LogWarnings)
                    {
                        Debug.LogWarning(DialogueDebug.Prefix + ": Localized text table '" + localizedTextTable.name + "' does not have a field: " + fieldName, this);
                    }
                }
                else
                {
                    text.text = localizedTextTable[fieldName];
                }
            }

#if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1)
            // Localize Dropdown:
            if (dropdown != null)
            {
                for (int i = 0; i < dropdown.options.Count; i++)
                {
                    if (i < fieldNames.Count)
                    {
                        dropdown.options[i].text = localizedTextTable[fieldNames[i]];
                    }
                }
                dropdown.captionText.text = localizedTextTable[fieldNames[dropdown.value]];
            }
#endif
        }
        private void Import()
        {
            if (!EditorUtility.DisplayDialog("Import CSV?",
                                             "Importing from CSV will overwrite the current contents. Are you sure?",
                                             "Import", "Cancel"))
            {
                return;
            }
            string newFilename = EditorUtility.OpenFilePanel("Import from CSV", EditorWindowTools.GetDirectoryName(csvFilename), "csv");

            if (!string.IsNullOrEmpty(newFilename))
            {
                csvFilename = newFilename;
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    csvFilename = csvFilename.Replace("/", "\\");
                }
                try {
                    using (StreamReader file = new StreamReader(csvFilename, Encoding.UTF8)) {
                        // Work with a temporary, new table:
                        LocalizedTextTable newTable = ScriptableObject.CreateInstance <LocalizedTextTable>();

                        // Read heading:
                        string[] values = CSVExporter.GetValues(file.ReadLine());
                        newTable.languages = new List <string>(values);
                        newTable.languages.RemoveAt(0);

                        // Read fields:
                        newTable.fields.Clear();
                        while (!file.EndOfStream)
                        {
                            values = CSVExporter.GetValues(file.ReadLine());
                            LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                            field.name = values[0];
                            for (int i = 1; i < values.Length; i++)
                            {
                                field.values.Add(values[i]);
                            }
                            newTable.fields.Add(field);
                        }

                        // If we got to the end, use the new table:
                        table.languages.Clear();
                        foreach (var newLanguage in newTable.languages)
                        {
                            table.languages.Add(newLanguage);
                        }
                        table.fields.Clear();
                        foreach (var newField in newTable.fields)
                        {
                            LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                            field.name   = newField.name;
                            field.values = new List <string>(newField.values);
                            table.fields.Add(field);
                        }
                        DestroyImmediate(newTable);
                    }
                } catch (System.Exception e) {
                    Debug.LogError(e.Message);
                    EditorUtility.DisplayDialog("Import Failed", "There was an error importing the CSV file.", "OK");
                }
                EditorUtility.DisplayDialog("Export Complete", "The localized text table was exported to CSV (comma-separated values) format. ", "OK");
            }
        }
示例#9
0
        private void Import()
        {
            if (!EditorUtility.DisplayDialog("Import CSV?",
                                             "Importing from CSV will overwrite the current contents. Are you sure?",
                                             "Import", "Cancel"))
            {
                return;
            }
            string newFilename = EditorUtility.OpenFilePanel("Import from CSV", EditorWindowTools.GetDirectoryName(csvFilename), "csv");

            if (!string.IsNullOrEmpty(newFilename))
            {
                csvFilename = newFilename;
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    csvFilename = csvFilename.Replace("/", "\\");
                }
                try
                {
                    // Read the source file and combine multiline rows:
                    var    sourceLines = new List <string>();
                    var    file        = new StreamReader(csvFilename, EncodingTypeTools.GetEncoding(encodingType));
                    string line;
                    while ((line = file.ReadLine()) != null)
                    {
                        sourceLines.Add(line.TrimEnd());
                    }
                    file.Close();
                    CombineMultilineSourceLines(sourceLines);
                    if (sourceLines.Count < 1)
                    {
                        throw new System.Exception("No lines read from CSV file.");
                    }

                    // Work with a temporary, new table:
                    LocalizedTextTable newTable = ScriptableObject.CreateInstance <LocalizedTextTable>();

                    // Read heading:
                    string[] values = CSVExporter.GetValues(sourceLines[0]);
                    sourceLines.RemoveAt(0);
                    newTable.languages = new List <string>(values);
                    newTable.languages.RemoveAt(0);

                    // Read fields:
                    newTable.fields.Clear();
                    while (sourceLines.Count > 0)
                    {
                        values = CSVExporter.GetValues(sourceLines[0]);
                        sourceLines.RemoveAt(0);
                        LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                        field.name = values[0];
                        for (int i = 1; i < values.Length; i++)
                        {
                            field.values.Add(values[i]);
                        }
                        newTable.fields.Add(field);
                    }

                    // If we got to the end, use the new table:
                    table.languages.Clear();
                    foreach (var newLanguage in newTable.languages)
                    {
                        table.languages.Add(newLanguage);
                    }
                    table.fields.Clear();
                    foreach (var newField in newTable.fields)
                    {
                        LocalizedTextTable.LocalizedTextField field = new LocalizedTextTable.LocalizedTextField();
                        field.name   = newField.name;
                        field.values = new List <string>(newField.values);
                        table.fields.Add(field);
                    }
                    DestroyImmediate(newTable);
                }
                catch (System.Exception e)
                {
                    Debug.LogError(e.Message);
                    EditorUtility.DisplayDialog("Import Failed", "There was an error importing the CSV file.", "OK");
                }
                EditorUtility.DisplayDialog("Import Complete", "The localized text table was imported from " + newFilename + ".", "OK");
            }
        }