private void DrawVariableMap() { float lblWidth = EditorGUIUtility.labelWidth; SerializedProperty varProp = serObj.FindProperty("variables"); variablesExpanded = EditorGUILayout.Foldout(variablesExpanded, "Variables:", true); if (variablesExpanded) { EditorGUIUtility.labelWidth = lblWidth * 0.334f; SerializedProperty keysProp = varProp.FindPropertyRelative("keys"); int numKeys = keysProp.arraySize; SerializedProperty valuesProp = varProp.FindPropertyRelative("values"); valuesProp.arraySize = numKeys; bool shouldScroll = numKeys >= 5; if (shouldScroll) { variableScrollPos = EditorGUILayout.BeginScrollView(variableScrollPos, GUILayout.Height(100f)); } for (int i = 0; i < numKeys; ++i) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(keysProp.GetArrayElementAtIndex(i), new GUIContent("Key " + (i + 1))); EditorGUILayout.PropertyField(valuesProp.GetArrayElementAtIndex(i), new GUIContent("Value " + (i + 1))); if (GUILayout.Button("x", GUILayout.Width(35f))) { keysProp.DeleteArrayElementAtIndex(i); valuesProp.DeleteArrayElementAtIndex(i); --numKeys; } EditorGUILayout.EndHorizontal(); } if (shouldScroll) { EditorGUILayout.EndScrollView(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { ++keysProp.arraySize; ++valuesProp.arraySize; ++varsCreated; //Get to a key we haven't used. This shouldn't be needed too often. while (variables.ContainsKey(varName + varsCreated)) { ++varsCreated; } keysProp.GetArrayElementAtIndex(keysProp.arraySize - 1).stringValue = varName + varsCreated; } if (numKeys > 0) { if (GUILayout.Button("-")) { --keysProp.arraySize; --valuesProp.arraySize; } } EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = lblWidth; } }