/// <inheritdoc /> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { LazyInitializeParameters(property); position.height = k_LineHeight; EditorGUI.LabelField(position, label); position.y += k_LineHeight; var width = position.width / 2 - 24; var keyRect = new Rect(position.x + 20, position.y, width, position.height); var valueRect = new Rect(position.x + width + 30, position.y, width, position.height); DrawAddRemoveButtons(keyRect, valueRect); EditorGUI.BeginProperty(position, label, property); foreach (var parameter in m_Parameters) { var key = parameter.Key; var value = parameter.Value; keyRect.y += k_LineHeight; valueRect.y += k_LineHeight; EditorGUI.BeginChangeCheck(); var newKey = EditorGUI.TextField(keyRect, key); if (EditorGUI.EndChangeCheck()) { MarkSceneAsDirty(); try { m_Parameters.Remove(key); m_Parameters.Add(newKey, value); } catch (Exception e) { Debug.Log(e.Message); } break; } EditorGUI.BeginChangeCheck(); value = EditorGUI.FloatField(valueRect, value); if (EditorGUI.EndChangeCheck()) { MarkSceneAsDirty(); m_Parameters[key] = value; break; } } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { CheckInitialize(property, label); position.height = lineHeight; EditorGUI.LabelField(position, label); EditorGUI.BeginProperty(position, label, property); foreach (var item in _Dictionary) { var key = item.Key; var value = item.Value; position.y += lineHeight; // This is the rectangle for the key var keyRect = position; keyRect.x += 20; keyRect.width /= 2; keyRect.width -= 24; EditorGUI.BeginChangeCheck(); var newKey = EditorGUI.TextField(keyRect, key); if (EditorGUI.EndChangeCheck()) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); try { _Dictionary.Remove(key); _Dictionary.Add(newKey, value); } catch (Exception e) { Debug.Log(e.Message); } break; } // This is the Rectangle for the value var valueRect = position; valueRect.x = position.width / 2 + 15; valueRect.width = keyRect.width - 18; EditorGUI.BeginChangeCheck(); value = EditorGUI.FloatField(valueRect, value); if (EditorGUI.EndChangeCheck()) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); _Dictionary[key] = value; break; } } // This is the rectangle for the Add button position.y += lineHeight; var AddButtonRect = position; AddButtonRect.x += 20; AddButtonRect.width /= 2; AddButtonRect.width -= 24; if (GUI.Button(AddButtonRect, new GUIContent("Add New", "Add a new item to the default reset paramters"), EditorStyles.miniButton)) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); AddNewItem(); } // This is the rectangle for the Remove button var RemoveButtonRect = position; RemoveButtonRect.x = position.width / 2 + 15; RemoveButtonRect.width = AddButtonRect.width - 18; if (GUI.Button(RemoveButtonRect, new GUIContent("Remove Last", "Remove the last item to the default reset paramters"), EditorStyles.miniButton)) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); RemoveLastItem(); } EditorGUI.EndProperty(); }