public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); position.width -= 34; position.height = 18; Rect valueRect = new Rect(position); valueRect.x += 15; valueRect.width -= 15; Rect foldButtonRect = new Rect(position); foldButtonRect.width = 15; dropdown = EditorGUI.Foldout(foldButtonRect, dropdown, ""); position.x += 15; position.width -= 15; SerializedProperty key = property.FindPropertyRelative("key"); key.stringValue = EditorGUI.TextField(position, key.stringValue); position.x += position.width + 2; position.width = 17; position.height = 17; Texture searchIcon = (Texture)Resources.Load("search"); GUIContent searchContent = new GUIContent(searchIcon, "Search"); if (GUI.Button(position, searchContent)) { TextLocalizerSearchWindow.Open(); } position.x += position.width + 2; Texture storeIcon = (Texture)Resources.Load("store"); GUIContent storeContent = new GUIContent(storeIcon); if (GUI.Button(position, storeContent)) { TextLocalizerEditWindow.Open(key.stringValue); } if (dropdown) { var value = LocalizationSystem.GetLocalizedValue(key.stringValue); GUIStyle style = GUI.skin.box; height = style.CalcHeight(new GUIContent(value), valueRect.width); valueRect.height = height; valueRect.y += 21; EditorGUI.LabelField(valueRect, value, EditorStyles.wordWrappedLabel); } EditorGUI.EndProperty(); }
public static void Open() { TextLocalizerSearchWindow window = ScriptableObject.CreateInstance <TextLocalizerSearchWindow>(); window.titleContent = new GUIContent("Localization Search"); Vector2 mouse = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); Rect r = new Rect(mouse.x - 450, mouse.y + 10, 10, 10); window.ShowAsDropDown(r, new Vector2(500, 300)); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); //Draw label position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); position.width -= 57; position.height = 18; //Adjust Rect Rect valueRect = new Rect(position); valueRect.x += 15; valueRect.width -= 15; //Create rect for foldout position.x -= 35; Rect foldButtonRect = new Rect(position); foldButtonRect.width = 15; dropdown = EditorGUI.Foldout(foldButtonRect, dropdown, ""); //Key Label position.x += 5; EditorGUI.LabelField(position, "Key", EditorStyles.boldLabel); position.x -= 5; position.x += 35; position.width -= 15; //Text field for the key SerializedProperty key = property.FindPropertyRelative("key"); key.stringValue = EditorGUI.TextField(position, key.stringValue); //Draw Search Button position.x += position.width + 2; position.width = 25; position.height = 25; GUIContent searchContent = EditorGUIUtility.IconContent("ViewToolZoom On"); if (GUI.Button(position, searchContent)) { TextLocalizerSearchWindow.Open(); } //Draw Add/Edit Button position.x += position.width + 2; GUIContent storeContent = EditorGUIUtility.IconContent("d_Toolbar Plus"); if (GUI.Button(position, storeContent)) { TextLocalizerEditWindow.Open(key.stringValue); } //If the dropdown is enabled, draw the translations if (dropdown) { if (languages == null) { GetLanguages(); } if (languages != null) { float startX = valueRect.x; for (int i = 0; i < languages.Length; i++) { //Draw label with the specific language and its translation valueRect.x = startX; var value = LocalizationSystem.GetLocalizedValue(key.stringValue, (LocalizationSystem.Language)i); GUIStyle style = GUI.skin.box; height = style.CalcHeight(new GUIContent(value), valueRect.width); //Language Label valueRect.height = height; valueRect.y += 21; EditorGUI.LabelField(valueRect, languages[i] + ":"); //Translation Value Label valueRect.x += position.width + 25; EditorGUI.LabelField(valueRect, value, EditorStyles.wordWrappedLabel); } } } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); position.width -= 34; position.height = 18; Rect valueRect = new Rect(position); valueRect.x += 15; valueRect.y += 20; valueRect.width -= 15; Rect foldButtonRectRect = new Rect(position); foldButtonRectRect.width = 15; dropdown = EditorGUI.Foldout(foldButtonRectRect, dropdown, ""); position.x += 15; position.width -= 15; SerializedProperty key = property.FindPropertyRelative("key"); key.stringValue = EditorGUI.TextField(position, key.stringValue); position.x += position.width + 2; position.width = 17; position.height = 17; Texture searchIcon = (Texture)Resources.Load("Localization/search"); GUIContent searchContent = new GUIContent(searchIcon); if (GUI.Button(position, searchContent)) { if (!TextLocalizerSearchWindow.IsOpen) { TextLocalizerSearchWindow.Open(); } } position.x += position.width + 2; Texture addIcon = (Texture)Resources.Load("Localization/add"); GUIContent addContent = new GUIContent(addIcon); if (GUI.Button(position, addContent)) { if (!TextLocalizerEditWindow.IsOpen) { TextLocalizerEditWindow.Open(key.stringValue); } } if (dropdown) { for (int i = 0; i < System.Enum.GetNames(typeof(LocalizationManager.LocalizedLanguage)).Length; i++) { var value = LocalizationManager.GetLocalizedValue(key.stringValue, (LocalizationManager.LocalizedLanguage)System.Enum.GetValues(typeof(LocalizationManager.LocalizedLanguage)).GetValue(i)); GUIStyle style = GUI.skin.box; height = style.CalcHeight(new GUIContent(value), valueRect.width); valueRect.height = height; valueRect.width += 21; valueRect.y = 20 * (i + 2) + 5; EditorGUI.LabelField(valueRect, value, EditorStyles.wordWrappedLabel); } } EditorGUI.EndProperty(); }