66
77public class ScriptableObjectEditorWindow : EditorWindow
88{
9+ public const string BASIC_FILTERS_PREF = "basic_filters" ;
10+ private const char SEPARATOR = '|' ; // Filtrelerde kullanýlmayacak özel bir karakter
11+
12+ public static string [ ] BasicFilters
13+ {
14+ get
15+ {
16+ string savedFilters = EditorPrefs . GetString ( BASIC_FILTERS_PREF , "" ) ;
17+ return string . IsNullOrEmpty ( savedFilters )
18+ ? new string [ 0 ]
19+ : savedFilters . Split ( new [ ] { SEPARATOR } , StringSplitOptions . RemoveEmptyEntries ) ;
20+ }
21+ set
22+ {
23+ string filtersString = string . Join ( SEPARATOR . ToString ( ) , value ) ;
24+ EditorPrefs . SetString ( BASIC_FILTERS_PREF , filtersString ) ;
25+ }
26+ }
27+
928 // layout:
1029 private readonly float PropertyMinWidth = 40 ;
1130 private readonly float PropertySpace = 5 ;
@@ -15,7 +34,7 @@ public class ScriptableObjectEditorWindow : EditorWindow
1534
1635 // data:
1736 private List < List < ScriptableObject > > groupedConfigs ; // Stores ScriptableObjects grouped by their class types in nested lists
18- private readonly List < Type > selectedTypes = new ( ) ; // Tracks which ScriptableObject types are currently selected for display
37+ private List < Type > selectedTypes = new ( ) ; // Tracks which ScriptableObject types are currently selected for display
1938 private List < Type > availableTypes = new ( ) ; // Holds all unique ScriptableObject types found in the project
2039
2140 // window:
@@ -121,12 +140,21 @@ private void LoadAvailableTypes()
121140 {
122141 // Scan the "ScriptableObjects" folder to find all unique ScriptableObject types
123142 availableTypes = Resources . LoadAll < ScriptableObject > ( "ScriptableObjects" ) . Select ( t => t . GetType ( ) ) . Distinct ( ) . ToList ( ) ;
124- if ( selectedTypes . Count > 0 )
143+ foreach ( var filter in BasicFilters )
125144 {
126- selectedTypes . Intersect ( availableTypes ) ;
145+ if ( string . IsNullOrEmpty ( filter ) )
146+ continue ;
147+ // Add any additional types specified in the basic filters
148+ var type = availableTypes . FirstOrDefault ( t => t . Name == filter ) ;
149+ if ( type != null )
150+ {
151+ selectedTypes . Add ( type ) ;
152+ }
127153 }
128- else
154+
155+ if ( selectedTypes . Count == 0 )
129156 {
157+ Debug . LogWarning ( "no saved filter found for ScriptableObject Editor Window" ) ;
130158 selectedTypes . AddRange ( availableTypes ) ;
131159 }
132160 }
@@ -314,14 +342,15 @@ public override void OnGUI(Rect rect)
314342 {
315343 SelectedTypes . Add ( type ) ; // Add the type to the selection list
316344 OnSelectionChanged . Invoke ( ) ;
345+ ScriptableObjectEditorWindow . BasicFilters = SelectedTypes . Select ( t => t . Name ) . ToArray ( ) ;
317346 }
318347 else if ( ! toggle && isSelected )
319348 {
320349 SelectedTypes . Remove ( type ) ; // Remove the type from the selection list
321350 OnSelectionChanged . Invoke ( ) ;
351+ ScriptableObjectEditorWindow . BasicFilters = SelectedTypes . Select ( t => t . Name ) . ToArray ( ) ;
322352 }
323353 }
324-
325354 // Close the scrollable area within the popup
326355 EditorGUILayout . EndScrollView ( ) ;
327356 }
0 commit comments