protected virtual void DrawEntryField(Rect position, SerializedProperty entry, int index) { var keyProperty = entry.FindPropertyRelative("key"); var typeProperty = entry.FindPropertyRelative("type"); var valuesProperty = entry.FindPropertyRelative("values"); ValueType type = (ValueType)typeProperty.enumValueIndex; float x = position.x; float y = position.y; float height = EditorGUIUtility.singleLineHeight; float width = position.width - HORIZONTAL_GAP * 2; Rect foldoutRect = new Rect(x + 15, y, 16, 16); var foldout = index == foldoutIndex; EditorGUI.BeginChangeCheck(); foldout = EditorGUI.Foldout(foldoutRect, foldout, GUIContent.none); if (EditorGUI.EndChangeCheck()) { foldoutIndex = foldout ? index : -1; this.entryList.index = foldoutIndex; } if (foldoutIndex != index) { Rect keyRect = new Rect(foldoutRect.xMax - 15, y, Mathf.Min(200, width * 0.4f), height); Rect typeRect = new Rect(keyRect.xMax + HORIZONTAL_GAP, y, Mathf.Min(120, width * 0.2f), height); Rect valueRect = new Rect(typeRect.xMax + HORIZONTAL_GAP, y, position.xMax - typeRect.xMax - HORIZONTAL_GAP, height); EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none); EditorGUI.LabelField(typeRect, type.ToString()); if (this.currLanguageIndex >= this.languages.Count) { this.currLanguageIndex = 0; } var valueProperty = valuesProperty.GetArrayElementAtIndex(this.currLanguageIndex); DrawValueField(valueRect, valueProperty, type); } else { y += height + VERTICAL_GAP; width = position.width + 40; Rect keyLabelRect = new Rect(x, y, Mathf.Min(200, width * 0.4f), height); Rect keyRect = new Rect(keyLabelRect.xMax + HORIZONTAL_GAP, y, width - keyLabelRect.width - HORIZONTAL_GAP, height); EditorGUI.LabelField(keyLabelRect, "Key"); EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none); y += height + VERTICAL_GAP; Rect typeLabelRect = new Rect(x, y, Mathf.Min(200, width * 0.4f), height); Rect typeRect = new Rect(typeLabelRect.xMax + HORIZONTAL_GAP, y, width - typeLabelRect.width - HORIZONTAL_GAP, height); EditorGUI.LabelField(typeLabelRect, "Type"); EditorGUI.LabelField(typeRect, type.ToString()); y += height + VERTICAL_GAP; float valueHeight = type == ValueType.String ? height * 2 : height; for (int i = 0; i < languages.Count; i++) { Rect languageRect = new Rect(x, y, Mathf.Min(200, width * 0.4f), height); Rect valueRect = new Rect(languageRect.xMax + HORIZONTAL_GAP, y, position.xMax - languageRect.xMax - HORIZONTAL_GAP, valueHeight); Language language = Language.GetLanguage(languages[i]); var valueProperty = valuesProperty.GetArrayElementAtIndex(i); string languageContent = string.Format("{0} [{1}]", language.Name, language.Code); if (!string.IsNullOrEmpty(language.Country)) { languageContent = string.Format("{0}({1}) [{2}]", language.Name, language.Country, language.Code); } EditorGUI.LabelField(languageRect, new GUIContent(languageContent, languageContent)); DrawValueField(valueRect, valueProperty, type, true); y += valueHeight + VERTICAL_GAP; } this.elementHeight = y - position.y + 5; } }
protected virtual void DrawEntryField(Rect position, SerializedProperty entry, int index) { var keyProperty = entry.FindPropertyRelative("key"); var typeProperty = entry.FindPropertyRelative("type"); var valueProperty = entry.FindPropertyRelative("value"); ValueType type = (ValueType)typeProperty.enumValueIndex; float x = position.x; float y = position.y; float height = EditorGUIUtility.singleLineHeight; float width = position.width - HORIZONTAL_GAP * 2; Rect foldoutRect = new Rect(x + 15, y, 16, 16); var foldout = index == foldoutIndex; EditorGUI.BeginChangeCheck(); foldout = EditorGUI.Foldout(foldoutRect, foldout, GUIContent.none); if (EditorGUI.EndChangeCheck()) { this.foldoutIndex = foldout ? index : -1; this.entryList.index = foldoutIndex; } if (foldoutIndex != index) { Rect keyRect = new Rect(foldoutRect.xMax - 15, y, Mathf.Min(200, width * 0.4f), height); Rect typeRect = new Rect(keyRect.xMax + HORIZONTAL_GAP, y, Mathf.Min(120, width * 0.2f), height); Rect valueRect = new Rect(typeRect.xMax + HORIZONTAL_GAP, y, position.xMax - typeRect.xMax - HORIZONTAL_GAP, height); EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none); EditorGUI.LabelField(typeRect, type.ToString()); DrawValueField(valueRect, valueProperty, type); } else { y += height + VERTICAL_GAP; width = position.width + 40; Rect keyLabelRect = new Rect(x, y, Mathf.Min(60, width * 0.2f), height); Rect keyRect = new Rect(keyLabelRect.xMax + HORIZONTAL_GAP, y, width - keyLabelRect.width - HORIZONTAL_GAP, height); EditorGUI.LabelField(keyLabelRect, "Key"); EditorGUI.PropertyField(keyRect, keyProperty, GUIContent.none); y += height + VERTICAL_GAP; Rect typeLabelRect = new Rect(x, y, Mathf.Min(60, width * 0.2f), height); Rect typeRect = new Rect(typeLabelRect.xMax + HORIZONTAL_GAP, y, width - typeLabelRect.width - HORIZONTAL_GAP, height); EditorGUI.LabelField(typeLabelRect, "Type"); EditorGUI.LabelField(typeRect, type.ToString()); y += height + VERTICAL_GAP; float valueHeight = type == ValueType.String ? height * 4 : height; Rect valueLabelRect = new Rect(x, y, Mathf.Min(60, width * 0.2f), height); Rect valueRect = new Rect(valueLabelRect.xMax + HORIZONTAL_GAP, y, width - valueLabelRect.width - HORIZONTAL_GAP, valueHeight); EditorGUI.LabelField(valueLabelRect, "Value"); DrawValueField(valueRect, valueProperty, type, true); y += valueHeight + VERTICAL_GAP; this.elementHeight = y - position.y + 5; } }