public void ReadData() { Localization.Initialize(); this._languages = Localization.GetLanguages(); //Select first language (EN) if (this._languages.Length > 0) { this._selectedLanguage = this._languages[Mathf.Max(this._selectedLanguageIndex, 0)]; this._data = Localization.SetLanguage(this._selectedLanguage); } }
public override void OnGUI(Rect rect) { EditorGUILayout.LabelField("Add New Language", EditorStyles.wordWrappedLabel); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Enter new language ALPHA2 key:"); this._newLanguage = EditorGUILayout.TextField(this._newLanguage); this._newLanguage.ToUpper(); if (this._newLanguage.Length > 2) { this._newLanguage = this._newLanguage.Substring(0, 2); } EditorGUILayout.Separator(); EditorGUILayout.HelpBox(this._info, this._infoType); EditorGUILayout.BeginHorizontal(); this._scrollPos = EditorGUILayout.BeginScrollView(this._scrollPos); foreach (var data in Localization.GetData()) { if (GUILayout.Button("x " + data.languageKey)) { this._dataToDelete = data; } } EditorGUILayout.EndScrollView(); if (this._dataToDelete != null) { if (EditorUtility.DisplayDialog("Delete Language Data", "Ae you sure you want to delete data for \"" + this._dataToDelete + "\". This action can not be undone?", "Delete", "Cancel")) { Localization.RemoveLanguageData(this._dataToDelete.languageKey); Localization.SaveData(); AssetDatabase.Refresh(); } } if (GUILayout.Button("Add")) { this.AddLanguage(); } EditorGUILayout.EndHorizontal(); }
void OnGUI() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Load Data")) { if (this._dirty) { if (EditorUtility.DisplayDialog("Changes not saved", "Discard changes?", "Discard", "Cancel")) { ReadData(); this._dirty = false; } } else { ReadData(); this._dirty = false; } } if (GUILayout.Button("Save Data")) { Localization.SaveData(); AssetDatabase.Refresh(); this._dirty = false; } if (GUILayout.Button("Import Excel File")) { //File browser / other stuff } EditorGUILayout.EndHorizontal(); if (this._data == null) { return; } EditorGUILayout.BeginHorizontal(); int lastIndex = this._selectedLanguageIndex; EditorGUILayout.LabelField("Select language:"); this._selectedLanguageIndex = EditorGUILayout.Popup(this._selectedLanguageIndex, this._languages); if (GUILayout.Button("Add Language")) { AddLanguage(); } EditorGUILayout.EndHorizontal(); if (this._selectedLanguageIndex >= 0) { if (lastIndex != this._selectedLanguageIndex) { this._selectedLanguage = this._languages[this._selectedLanguageIndex]; this._data = Localization.SetLanguage(this._selectedLanguage); } DrawPairs(); if (GUILayout.Button("Add Entry")) { AddPair(); } } }