|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using UnityEditor; |
| 5 | +using UnityEngine; |
| 6 | + |
| 7 | +namespace ScriptableObjectManager |
| 8 | +{ |
| 9 | + |
| 10 | + // Custom Popup Window for Config Type Selection |
| 11 | + internal class ConfigTypeSelectionPopup : PopupWindowContent |
| 12 | + { |
| 13 | + private readonly List<Type> SelectedTypes; |
| 14 | + private readonly List<Type> AvailableTypes; |
| 15 | + private readonly Action OnSelectionChanged; |
| 16 | + private Vector2 ScrollPos = new(); |
| 17 | + |
| 18 | + public ConfigTypeSelectionPopup(List<Type> selectedTypes, Action onSelectionChanged, List<Type> availableTypes) |
| 19 | + { |
| 20 | + this.SelectedTypes = selectedTypes; |
| 21 | + this.OnSelectionChanged = onSelectionChanged; |
| 22 | + this.AvailableTypes = availableTypes; |
| 23 | + } |
| 24 | + |
| 25 | + public override Vector2 GetWindowSize() |
| 26 | + { |
| 27 | + return new Vector2(200, 400); // Define the dimensions of the popup window |
| 28 | + } |
| 29 | + |
| 30 | + public override void OnGUI(Rect rect) |
| 31 | + { |
| 32 | + GUILayout.Label("Select Config Types", EditorStyles.boldLabel); |
| 33 | + |
| 34 | + if (AvailableTypes.Count > 0) |
| 35 | + { |
| 36 | + ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos); |
| 37 | + |
| 38 | + // Display each available type with a toggle to enable or disable it |
| 39 | + foreach (var type in AvailableTypes) |
| 40 | + { |
| 41 | + bool isSelected = SelectedTypes.Contains(type); |
| 42 | + bool toggle = EditorGUILayout.Toggle(type.Name, isSelected); |
| 43 | + |
| 44 | + if (toggle && !isSelected) |
| 45 | + { |
| 46 | + SelectedTypes.Add(type); // Add the type to the selection list |
| 47 | + OnSelectionChanged.Invoke(); |
| 48 | + ScriptableObjectEditorWindow.BasicFilters = SelectedTypes.Select(t => t.Name).ToArray(); |
| 49 | + } |
| 50 | + else if (!toggle && isSelected) |
| 51 | + { |
| 52 | + SelectedTypes.Remove(type); // Remove the type from the selection list |
| 53 | + OnSelectionChanged.Invoke(); |
| 54 | + ScriptableObjectEditorWindow.BasicFilters = SelectedTypes.Select(t => t.Name).ToArray(); |
| 55 | + } |
| 56 | + } |
| 57 | + // Close the scrollable area within the popup |
| 58 | + EditorGUILayout.EndScrollView(); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments