private static void EnumAddGUI <TKey, TValue>(this SDictionary <TKey, TValue> dict, GetNew <TValue> getNew) where TKey : System.Enum { if (EditorGUILayout.DropdownButton(new GUIContent("+"), FocusType.Keyboard)) { GenericMenu menu = new GenericMenu(); foreach (var t in EnumUtils.GetValues <TKey>()) { if (!dict.ContainsKey(t)) { menu.AddItem(new GUIContent(t.ToString()), false, (obj) => dict.Add((TKey)obj, getNew()), t); } } menu.ShowAsContext(); } }
private static void StringAddGUI <TValue>(SDictionary <string, TValue> dict, ref string toAdd, GetNew <TValue> getNew) { EditorGUILayout.LabelField("New:", GUILayout.Width(45)); toAdd = EditorGUILayout.TextField(toAdd); if (GUILayout.Button(new GUIContent("Add"), GUILayout.Width(45))) { if (!string.IsNullOrWhiteSpace(toAdd) && !dict.ContainsKey(toAdd)) { dict.Add(toAdd, getNew()); } toAdd = string.Empty; GUIUtility.keyboardControl = 0; } }