protected void DrawRecord(int recordIndex, out bool recordRemoved) { recordRemoved = false; PrefsRecord record = filteredRecords[recordIndex]; CustomEditorGUI.Separator(); using (CustomEditorGUI.Horizontal(CustomEditorGUI.PanelWithBackground)) { if (GUILayout.Button(new GUIContent("X", "Delete this pref."), CustomEditorGUI.CompactButton, GUILayout.Width(20))) { record.Delete(); allRecords.Remove(record); filteredRecords.Remove(record); recordRemoved = true; return; } GUI.enabled = record.dirtyValue || record.dirtyKey && record.prefType != PrefsRecord.PrefsType.Unknown; if (GUILayout.Button(new GUIContent("S", "Save changes in this pref."), CustomEditorGUI.CompactButton, GUILayout.Width(20))) { record.Save(); GUIUtility.keyboardControl = 0; } GUI.enabled = true; GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; GUI.enabled = true; if (GUILayout.Button(new GUIContent("...", "Other operations"), CustomEditorGUI.CompactButton, GUILayout.Width(25))) { ShowOtherMenu(record); } Color guiColor = GUI.color; GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; record.Key = EditorGUILayout.TextField(record.Key, GUILayout.MaxWidth(200), GUILayout.MinWidth(50)); if (record.prefType == PrefsRecord.PrefsType.String) { // to avoid TextMeshGenerator error because of too much characters if (record.StringValue.Length > 16382) { GUI.enabled = false; EditorGUILayout.TextField(STRING_TOO_LONG, GUILayout.MinWidth(150)); GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; } else { record.StringValue = EditorGUILayout.TextField(record.StringValue, GUILayout.MinWidth(150)); } } else if (record.prefType == PrefsRecord.PrefsType.Int) { record.IntValue = EditorGUILayout.IntField(record.IntValue, GUILayout.MinWidth(150)); } else if (record.prefType == PrefsRecord.PrefsType.Float) { record.FloatValue = EditorGUILayout.FloatField(record.FloatValue, GUILayout.MinWidth(150)); } else { GUI.enabled = false; EditorGUILayout.TextField(UNKNOWN_VALUE_DESCRIPTION, GUILayout.MinWidth(150)); GUI.enabled = record.prefType != PrefsRecord.PrefsType.Unknown; } GUI.color = guiColor; GUI.enabled = true; EditorGUILayout.LabelField(record.DisplayType, GUILayout.Width(70)); } }
private void OnGUI() { if (allRecords == null) { allRecords = new List <PrefsRecord>(); } if (filteredRecords == null) { filteredRecords = new List <PrefsRecord>(); } using (CustomEditorGUI.Horizontal(CustomEditorGUI.Toolbar)) { if (GUILayout.Button(new GUIContent("+", "Create new prefs record."), EditorStyles.toolbarButton, GUILayout.Width(20))) { addingNewRecord = true; } if (GUILayout.Button(new GUIContent("Refresh", "Re-read and re-parse all prefs."), EditorStyles.toolbarButton, GUILayout.Width(50))) { RefreshData(); GUIUtility.keyboardControl = 0; scrollPosition = Vector2.zero; recordsCurrentPage = 0; } EditorGUI.BeginChangeCheck(); sortingType = (SortingType)EditorGUILayout.EnumPopup(sortingType, EditorStyles.toolbarDropDown, GUILayout.Width(110)); if (EditorGUI.EndChangeCheck()) { ApplySorting(); } GUILayout.Space(10); EditorGUI.BeginChangeCheck(); searchPattern = CustomEditorGUI.SearchToolbar(searchPattern); if (EditorGUI.EndChangeCheck()) { ApplyFiltering(); } } if (addingNewRecord) { using (CustomEditorGUI.Horizontal(CustomEditorGUI.PanelWithBackground)) { string[] types = { "String", "Int", "Float" }; newRecordType = EditorGUILayout.Popup(newRecordType, types, GUILayout.Width(50)); Color guiColor = GUI.color; GUILayout.Label("Key:", GUILayout.ExpandWidth(false)); newRecordKey = EditorGUILayout.TextField(newRecordKey); GUILayout.Label("Value:", GUILayout.ExpandWidth(false)); if (newRecordType == 0) { newRecordStringValue = EditorGUILayout.TextField(newRecordStringValue); } else if (newRecordType == 1) { newRecordIntValue = EditorGUILayout.IntField(newRecordIntValue); } else { newRecordFloatValue = EditorGUILayout.FloatField(newRecordFloatValue); } GUI.color = guiColor; if (GUILayout.Button("OK", CustomEditorGUI.CompactButton, GUILayout.Width(30))) { if (string.IsNullOrEmpty(newRecordKey) || (newRecordType == 0 && string.IsNullOrEmpty(newRecordStringValue)) || (newRecordType == 1 && newRecordIntValue == 0) || (newRecordType == 2 && Math.Abs(newRecordFloatValue) < 0.00000001f)) { ShowNotification(new GUIContent("Please fill in the pref first!")); } else { PrefsRecord newRecord; if (newRecordType == 0) { newRecord = new PrefsRecord(newRecordKey, newRecordStringValue); } else if (newRecordType == 1) { newRecord = new PrefsRecord(newRecordKey, newRecordIntValue); } else { newRecord = new PrefsRecord(newRecordKey, newRecordFloatValue); } if (newRecord.Save()) { allRecords.Add(newRecord); ApplySorting(); CloseNewRecordPanel(); } } } if (GUILayout.Button("Cancel", CustomEditorGUI.CompactButton, GUILayout.Width(60))) { CloseNewRecordPanel(); } } } using (CustomEditorGUI.Vertical(CustomEditorGUI.PanelWithBackground)) { GUILayout.Space(5); DrawRecordsPages(); GUILayout.Space(5); } }
private void DrawRecordsPages() { recordsTotalPages = Math.Max(1, (int)Math.Ceiling((double)filteredRecords.Count / RECORDS_PER_PAGE)); if (recordsCurrentPage < 0) { recordsCurrentPage = 0; } if (recordsCurrentPage + 1 > recordsTotalPages) { recordsCurrentPage = recordsTotalPages - 1; } int fromRecord = recordsCurrentPage * RECORDS_PER_PAGE; int toRecord = fromRecord + Math.Min(RECORDS_PER_PAGE, filteredRecords.Count - fromRecord); if (recordsTotalPages > 1) { GUILayout.Label("Prefs " + fromRecord + " - " + toRecord + " from " + filteredRecords.Count); } scrollPosition = GUILayout.BeginScrollView(scrollPosition); for (int i = fromRecord; i < toRecord; i++) { bool recordRemoved; DrawRecord(i, out recordRemoved); if (recordRemoved) { break; } } GUILayout.EndScrollView(); if (recordsTotalPages <= 1) { return; } GUILayout.Space(5); using (CustomEditorGUI.Horizontal()) { GUILayout.FlexibleSpace(); GUI.enabled = recordsCurrentPage > 0; if (GUILayout.Button("<<", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage = 0; scrollPosition = Vector2.zero; } if (GUILayout.Button("<", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage--; scrollPosition = Vector2.zero; } GUI.enabled = true; GUILayout.Label(recordsCurrentPage + 1 + " of " + recordsTotalPages, CustomEditorGUI.CenteredLabel, GUILayout.Width(100)); GUI.enabled = recordsCurrentPage < recordsTotalPages - 1; if (GUILayout.Button(">", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage++; scrollPosition = Vector2.zero; } if (GUILayout.Button(">>", GUILayout.Width(50))) { RemoveNotification(); recordsCurrentPage = recordsTotalPages - 1; scrollPosition = Vector2.zero; } GUI.enabled = true; GUILayout.FlexibleSpace(); } }