private void OnEnable() { if (!isLoaded) { isLoaded = true; } using (EditorLocalization.EditorLocalizationValues.BeginScope()) { titleContent = new GUIContent("Localization".Localization()); if (itemDatas == null) { itemDatas = new ItemData[0]; } if (baseData == null) { baseData = new ItemData(); } baseData.Load(); foreach (var item in itemDatas) { item.Load(); } if (allLangNames == null) { allLangNames = new string[0]; allLangPaths = new string[0]; } EditorLocalization.GetValueDrawer("string"); } }
void GUIItemNode(ItemData item, string key, LocalizationValue value, int itemIndex) { ILocalizationValueDrawer drawer; drawer = EditorLocalization.GetValueDrawer(value.TypeName); if (drawer == null) { drawer = EditorLocalization.GetValueDrawer("string"); } bool ineritValue = !item.values.ContainsKey(key); if (!ineritValue) { value.Value = drawer.OnGUI(value.Value); item.values[key] = value; if (baseData.lang != item.lang) { if (GUILayout.Button("T", TranslateButtonStyle, GUILayout.ExpandWidth(false))) { Translate(baseData, new List <TranslateItem>() { new TranslateItem() { itemData = item, key = key } }); //EditorUtility.DisplayProgressBar("Translate", "", 0f); //GoogleTranslator.Process(itemDatas[0].lang, item.lang, (string)baseData.values[key].Value, (b, result) => //{ // EditorUtility.ClearProgressBar(); // if (b) // { // value.Value = result; // item.values[key] = value; // DirtyData(item); // } //}); } } } else { var baseValue = baseData.values[key]; using (new GUIx.Scopes.ColorScope(GUI.color * new Color(1, 1, 1, 0.5f))) using (var checker = new EditorGUI.ChangeCheckScope()) { object newValue = drawer.OnGUI(baseValue.Value); if (checker.changed) { var clone = baseValue.Clone(); clone.Value = newValue; item.values[key] = clone; GUI.changed = true; } } } }
void GUINewItem() { if (string.IsNullOrEmpty(baseData.path)) { return; } string error = null; using (new GUILayout.HorizontalScope()) { searchKey = EditorGUILayoutx.SearchTextField(searchKey, GUIContent.none, GUILayout.Width(EditorGUIUtility.labelWidth)); int typeNameIndex = 0; string[] typeNames = EditorLocalization.GetValueTypeNames().ToArray(); for (int i = 0; i < typeNames.Length; i++) { if (typeNames[i] == newValueTypeName) { typeNameIndex = i; break; } } float width = (Screen.width - EditorGUIUtility.labelWidth) * 0.3f; width = Mathf.Min(width, 150); typeNameIndex = EditorGUILayout.Popup(typeNameIndex, typeNames.Select(o => ("type_" + o).Localization()).ToArray(), GUILayout.Width(width)); newValueTypeName = typeNames[typeNameIndex]; string newKeyCurrent; newKey = EditorGUILayoutx.DelayedPlaceholderField(newKey ?? string.Empty, out newKeyCurrent, new GUIContent("New Key".Localization()) /*, GUILayout.Width(EditorGUIUtility.labelWidth)*/); if (!string.IsNullOrEmpty(newKeyCurrent)) { if (baseData.values.ContainsKey(newKeyCurrent)) { error = string.Format("key <{0}> base exists", newKeyCurrent); } } if (!string.IsNullOrEmpty(newKey) && error == null) { var value = new LocalizationValue(newValueTypeName, Localization.GetValueProvider(newValueTypeName).DefaultValue); if (newValueTypeName == "string") { value.Value = newKey; } baseData.values[newKey] = value; newKey = string.Empty; GUIUtility.keyboardControl = -1; DiryBaseData(); } } if (error != null) { EditorGUILayout.HelpBox(error, MessageType.Error); } }