/// <summary> /// Draws the new item. /// </summary> void DrawNewEditor() { EditorGUILayout.BeginVertical("box"); _newItemTypeEditor = (ItemType)EditorGUILayout.EnumPopup(new GUIContent("Type", "The type of value this prefs item will contain"), _newItemTypeEditor); _newItemKeyEditor = EditorGUILayout.TextField(new GUIContent("Key", "Aunique key for this prefs item"), _newItemKeyEditor); switch (_newItemTypeEditor) { case ItemType.Int: _newItemValueIntEditor = EditorGUILayout.IntField(new GUIContent("Value", "This items value"), _newItemValueIntEditor); break; case ItemType.Float: _newItemValueFloatEditor = EditorGUILayout.FloatField(new GUIContent("Value", "This items value"), _newItemValueFloatEditor); break; case ItemType.String: _newItemValueStringEditor = EditorGUILayout.TextField(new GUIContent("Value", "This items value"), _newItemValueStringEditor); break; } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (ButtonTrimmed("Add", null, EditorStyles.miniButtonRight, "Create a new prefs item with the values entered above.")) { if (!string.IsNullOrEmpty(_newItemKeyEditor)) { PrefsEntry newPrefsEntry = null; switch (_newItemTypeEditor) { case ItemType.Int: newPrefsEntry = new PrefsEntry(_newItemKeyEditor, _newItemValueIntEditor, false, false); break; case ItemType.Float: newPrefsEntry = new PrefsEntry(_newItemKeyEditor, _newItemValueFloatEditor, false, false); break; case ItemType.String: newPrefsEntry = new PrefsEntry(_newItemKeyEditor, _newItemValueStringEditor, false, false); break; } newPrefsEntry.MatchesFilter = _newItemKey.IndexOf(_editorPrefsFilter + "", StringComparison.OrdinalIgnoreCase) >= 0; newPrefsEntry.Save(); _editorPrefsEntries.Add(newPrefsEntry); } ClearFocus(); _showNewEditor = false; } if (ButtonTrimmed("Cancel", null, EditorStyles.miniButtonRight, "Close this popup without adding a prefs item")) { _showNewEditor = false; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
/// <summary> /// Draws the new item. /// </summary> void DrawNew() { EditorGUILayout.BeginVertical("box"); _newItemType = (ItemType)EditorGUILayout.EnumPopup(new GUIContent("Type", "The type of value this prefs item will contain"), _newItemType); _newItemKey = EditorGUILayout.TextField(new GUIContent("Key", "Aunique key for this prefs item"), _newItemKey); switch (_newItemType) { case ItemType.Int: _newItemValueInt = EditorGUILayout.IntField(new GUIContent("Value", "This items value"), _newItemValueInt); break; case ItemType.Float: _newItemValueFloat = EditorGUILayout.FloatField(new GUIContent("Value", "This items value"), _newItemValueFloat); break; case ItemType.String: _newItemValueString = EditorGUILayout.TextField(new GUIContent("Value", "This items value"), _newItemValueString); break; } _newItemEncrypted = EditorGUILayout.Toggle(new GUIContent("Encrypted", "Specifies whether this item should be encrypted."), _newItemEncrypted); if (_newItemEncrypted && string.IsNullOrEmpty(_passPhrase)) { EditorGUILayout.HelpBox("Please ensure you specify a pass phrase before adding encrypted items.", MessageType.Warning); } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (ButtonTrimmed("Add", null, EditorStyles.miniButtonRight, "Create a new prefs item with the values entered above.")) { if (!string.IsNullOrEmpty(_newItemKey)) { PrefsEntry newPrefsEntry = null; switch (_newItemType) { case ItemType.Int: newPrefsEntry = new PrefsEntry(_newItemKey, _newItemValueInt, _newItemEncrypted, true); break; case ItemType.Float: newPrefsEntry = new PrefsEntry(_newItemKey, _newItemValueFloat, _newItemEncrypted, true); break; case ItemType.String: newPrefsEntry = new PrefsEntry(_newItemKey, _newItemValueString, _newItemEncrypted, true); break; } newPrefsEntry.MatchesFilter = _newItemKey.IndexOf(_playerPrefsFilter + "", StringComparison.OrdinalIgnoreCase) >= 0; newPrefsEntry.Save(); _playerPrefsEntries.Add(newPrefsEntry); } ClearFocus(); _showNew = false; } if (ButtonTrimmed("Cancel", null, EditorStyles.miniButtonRight, "Close this popup without adding a prefs item")) { _showNew = false; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }