private static void DisplayMergeItem(ref MergeItem item, string message) { if (!string.IsNullOrEmpty(item.path)) { GUILayout.Label(item.path); } if (GUILayout.Button(message)) { var path = LocalizationEditorUtils.GetFilePathFromUser("Select a localisation data file"); if (!string.IsNullOrEmpty(path)) { string jsonData = File.ReadAllText(path); item.data = JsonUtility.FromJson <LocalizationData>(jsonData); LocalizationEditorUtils.LastPath = path; if (LocalizationEditorUtils.IsDataInvalid(item.data)) { LocalizationEditorUtils.OnError("Couldn't read data from provided file! Please provide a valid file"); } else { item.path = path; LocalizationEditorUtils.LastPath = path; } } } GUILayout.Space(50.0f); }
public void ReadXml(string fileName) { string sheetName = "Sheet1"; Workbook workbook = Workbook.CreatWorkbook(fileName, sheetName); Sheet sheet = workbook._sheet; if (sheet == null) { Debug.LogError("Can't find " + sheetName + " in " + fileName); return; } Dictionary <string, List <LanguageTextEntry> > languages = new Dictionary <string, List <LanguageTextEntry> >(); List <string> langKeys = sheet._rows[0]._cells; for (int i = 1; i < langKeys.Count; i++) { string lang = langKeys[i]; languages.Add(lang, new List <LanguageTextEntry>()); } for (int i = 1; i < sheet._rows.Count; i++) { Row row = sheet._rows[i]; string IDS = row._cells[0]; for (int j = 1; j < row._cells.Count; j++) { LanguageTextEntry textEntry = new LanguageTextEntry(); textEntry.key = IDS; textEntry.text = row._cells[j]; string lang = row._key[j]; List <LanguageTextEntry> textEntryList = languages[lang]; textEntryList.Add(textEntry); } } for (int i = 1; i < langKeys.Count; i++) { string lang = langKeys[i]; List <LanguageTextEntry> textEntryList = languages[lang]; string path = MultiLanguageAssetPostProcessor.MULTILANGUAGE_ASSETS_FOLDER; LocalizationEditorUtils.CreateDirectoryIfNotExist(path, "Fonts", lang); // Create config file that contain key-value strings. CreateLanguageDataBase(lang, textEntryList); // Create config file that contain uv and size information. CreateLanguageDictionary(lang, textEntryList); } }
private void SaveData() { //opens a save file panel and saves user-inputted path filePath = LocalizationEditorUtils.GetFilePathFromUser(); //if the path is valid if (!string.IsNullOrEmpty(filePath)) { //serialize pairs string jsonData = JsonUtility.ToJson(data); //write File.WriteAllText(filePath, jsonData); saved = true; LocalizationEditorUtils.LastPath = filePath; } }
private void LoadData() { if (!SaveCheck()) { return; } filePath = LocalizationEditorUtils.GetFilePathFromUser(); if (!string.IsNullOrEmpty(filePath)) { string jsonData = File.ReadAllText(filePath); data = JsonUtility.FromJson <LocalizationData>(jsonData); saved = true; LocalizationEditorUtils.LastPath = filePath; } }
/// <summary> /// Makes the atlas. /// </summary> protected void MakeAtlas(string lang, ref LocalizationFontConfig.FontConfig config) { string filename = System.IO.Path.Combine(_toolDirectory, ToolAtlasMaker); string path = LocalizationEditorUtils.CreateDirectoryIfNotExist(_workDirectory, "Fonts", lang); config._atlasFile = System.IO.Path.Combine(path, config._fontName + ".png"); LocalizationCommand cmd = new LocalizationCommand("python"); cmd.SetRequiredParams(filename, config._imagesDir, config._atlasFile); cmd.AddOptionalParams("-p", config._padding); cmd.Execute(); _buildProgress += _buildstep; EditorUtility.DisplayCancelableProgressBar("Fonts maker", "Building...", _buildProgress); }
/// <summary> /// Creates the images. /// </summary> protected void CreateImages(string lang, ref LocalizationFontConfig.FontConfig config, string charsetFile) { string filename = System.IO.Path.Combine(_toolDirectory, ToolTTF2Images); LocalizationCommand cmd = new LocalizationCommand(filename); config._imagesDir = LocalizationEditorUtils.CreateDirectoryIfNotExist(_toolDirectory, "Temp", lang, config._fontName); config._font_info = System.IO.Path.Combine(config._imagesDir, "font_info.txt"); cmd.SetRequiredParams(config._ttfFile, config._fontSize, config._imagesDir); cmd.AddOptionalParams("-p", config._border); cmd.AddOptionalParams("-C", charsetFile); cmd.Execute(); _buildProgress += _buildstep; EditorUtility.DisplayCancelableProgressBar("Fonts maker", "Building...", _buildProgress); }
private void OnGUI() { DisplayMergeItem(ref first, "Select first data"); DisplayMergeItem(ref second, "Select second data"); LocalizationEditorUtils.DrawDivider(); bool disabled = string.IsNullOrEmpty(first.path) || string.IsNullOrEmpty(second.path); EditorGUI.BeginDisabledGroup(disabled); if (GUILayout.Button("Merge")) { MergeFiles(); } if (disabled) { EditorGUI.EndDisabledGroup(); } }
/// <summary> /// Generates the fnt. /// </summary> protected void GenerateFnt(string lang, ref LocalizationFontConfig.FontConfig config) { string filename = System.IO.Path.Combine(_toolDirectory, ToolFntMaker); string path = LocalizationEditorUtils.CreateDirectoryIfNotExist(_workDirectory, "Fonts", lang); string fntFile = System.IO.Path.Combine(path, config._fontName + ".fnt"); string txfFile = System.IO.Path.Combine(path, config._fontName + ".txt"); path = System.IO.Path.Combine(path, config._fontName + ".config"); LocalizationCommand cmd = new LocalizationCommand("python"); cmd.SetRequiredParams(filename, path, config._atlasFile, config._font_info); cmd.Execute(); // Rename *.fnt to *.txt System.IO.File.Delete(txfFile); System.IO.File.Move(fntFile, txfFile); _buildProgress += _buildstep; EditorUtility.DisplayCancelableProgressBar("Fonts maker", "Building...", _buildProgress); }
public static void CreateFontsConfig() { LocalizationEditorUtils.CreateScriptable <LocalizationFontConfig>(); }
public static void CreateLanguageFontSet() { LocalizationEditorUtils.CreateScriptable <LocalizationFontDataSet>(); }
private void DisplayDataFields() { filter = EditorGUILayout.TextField("Search", filter, GUILayout.ExpandWidth(true)); GUILayout.Space(20); EditorGUILayout.LabelField(new GUIContent { text = "<b>Data : </b>" }, new GUIStyle { fontSize = 20, richText = true }); GUILayout.Space(10); scrollView = EditorGUILayout.BeginScrollView(scrollView); SerializedObject serializedObject = new SerializedObject(this); SerializedProperty keyValuePairListProperty = serializedObject.FindProperty("data.keyValuePairs"); for (int i = 0; i < keyValuePairListProperty.arraySize; i++) { var keyValuePairProp = keyValuePairListProperty.GetArrayElementAtIndex(i); var keyProp = keyValuePairProp.FindPropertyRelative("key"); var valueProp = keyValuePairProp.FindPropertyRelative("value"); if (filter == "" || keyProp.stringValue.StartsWith(filter)) { if (EditorGUILayout.PropertyField(keyValuePairProp)) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(keyProp); EditorGUILayout.PropertyField(valueProp, GUILayout.MinHeight(100.0f)); if (EditorGUI.EndChangeCheck()) { saved = false; } } LocalizationEditorUtils.DrawDivider(); GUILayout.Space(10.0f); } } serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndScrollView(); EditorGUILayout.Separator(); if (GUILayout.Button("Add Pair")) { data.keyValuePairs.Add(new KeyValuePair()); } GUILayout.Space(20.0f); EditorGUI.BeginDisabledGroup(saved); if (filePath != null && (GUILayout.Button("Save File") || (EditorGUI.actionKey && sPressed))) { LocalizationEditorUtils.SaveDataToSetPath(filePath, data); saved = true; Repaint(); } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Save File As...")) { SaveData(); } if (GUILayout.Button("Sort")) { SortData(); } }
void MergeFiles() { var firstDict = new Dictionary <string, string>(); var secondDict = new Dictionary <string, string>(); EditorUtility.DisplayProgressBar("Merging data...", "Please stand by", 0); foreach (var pair in first.data.keyValuePairs) { if (!firstDict.ContainsKey(pair.key)) { firstDict.Add(pair.key, pair.value); } } foreach (var pair in second.data.keyValuePairs) { if (!secondDict.ContainsKey(pair.key)) { secondDict.Add(pair.key, pair.value); } } foreach (var key in firstDict.Keys) { if (!secondDict.ContainsKey(key)) { secondDict.Add(key, firstDict[key]); } } EditorUtility.DisplayProgressBar("Merging data...", "Please stand by", 50); foreach (var key in secondDict.Keys) { if (!firstDict.ContainsKey(key)) { firstDict.Add(key, secondDict[key]); } } EditorUtility.DisplayProgressBar("Merging data...", "Please stand by", 100); first.data.keyValuePairs.Clear(); second.data.keyValuePairs.Clear(); foreach (var key in firstDict.Keys) { var a = new KeyValuePair(); a.key = key; a.value = firstDict[key]; first.data.keyValuePairs.Add(a); } LocalizationEditorUtils.SaveDataToSetPath(first.path, first.data); foreach (var key in secondDict.Keys) { var a = new KeyValuePair(); a.key = key; a.value = secondDict[key]; second.data.keyValuePairs.Add(a); } LocalizationEditorUtils.SaveDataToSetPath(second.path, second.data); EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("Operation successful!", "Your data has been merged successfully", "OK"); }