public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var firstLine = position; firstLine.height = EditorGUIUtility.singleLineHeight; EditorGUI.PropertyField(firstLine, property); if (property.isExpanded) { var secondLine = firstLine; secondLine.y += EditorGUIUtility.singleLineHeight; EditorGUIUtility.labelWidth = 50f; secondLine.x += 15f; // indentation secondLine.width -= 15f; var secondLine_key = secondLine; var buttonWidth = 60f; secondLine_key.width -= buttonWidth; // assign button secondLine_key.width /= 2f; var secondLineValue = secondLine_key; secondLineValue.x += secondLineValue.width; if (GetTemplateValueProp(property).hasVisibleChildren) { // if the value has children, indent to make room for fold arrow secondLineValue.x += 15; secondLineValue.width -= 15; } var secondLineButton = secondLineValue; secondLineButton.x += secondLineValue.width; secondLineButton.width = buttonWidth; var kHeight = EditorGUI.GetPropertyHeight(GetTemplateKeyProp(property)); var vHeight = EditorGUI.GetPropertyHeight(GetTemplateValueProp(property)); var extraHeight = Mathf.Max(kHeight, vHeight); secondLine_key.height = kHeight; secondLineValue.height = vHeight; EditorGUI.PropertyField(secondLine_key, GetTemplateKeyProp(property), true); EditorGUI.PropertyField(secondLineValue, GetTemplateValueProp(property), true); var keysProp = GetKeysProp(property); var valuesProp = GetValuesProp(property); var numLines = keysProp.arraySize; if (GUI.Button(secondLineButton, "Assign")) { bool assignment = false; for (int i = 0; i < numLines; i++) { // Try to replace existing value if (SerializedPropertyExtension.EqualBasics(GetIndexedItemProp(keysProp, i), GetTemplateKeyProp(property))) { SerializedPropertyExtension.CopyBasics(GetTemplateValueProp(property), GetIndexedItemProp(valuesProp, i)); assignment = true; break; } } if (!assignment) { // Create a new value keysProp.arraySize += 1; valuesProp.arraySize += 1; SerializedPropertyExtension.CopyBasics(GetTemplateKeyProp(property), GetIndexedItemProp(keysProp, numLines)); SerializedPropertyExtension.CopyBasics(GetTemplateValueProp(property), GetIndexedItemProp(valuesProp, numLines)); } } for (int i = 0; i < numLines; i++) { secondLine_key.y += extraHeight; secondLineValue.y += extraHeight; secondLineButton.y += extraHeight; kHeight = EditorGUI.GetPropertyHeight(GetIndexedItemProp(keysProp, i)); vHeight = EditorGUI.GetPropertyHeight(GetIndexedItemProp(valuesProp, i)); extraHeight = Mathf.Max(kHeight, vHeight); secondLine_key.height = kHeight; secondLineValue.height = vHeight; EditorGUI.PropertyField(secondLine_key, GetIndexedItemProp(keysProp, i), true); EditorGUI.PropertyField(secondLineValue, GetIndexedItemProp(valuesProp, i), true); if (GUI.Button(secondLineButton, "Remove")) { keysProp.DeleteArrayElementAtIndex(i); valuesProp.DeleteArrayElementAtIndex(i); } } } EditorGUI.EndProperty(); }