66
77public class ScriptableObjectEditorWindow : EditorWindow
88{
9+ //prefs:
910 public const string BASIC_FILTERS_PREF = "basic_filters" ;
11+ public const string PROPERTY_SPACE_PREF = "property_space" ;
1012 private const char SEPARATOR = '|' ; // Filtrelerde kullanýlmayacak özel bir karakter
1113
1214 public static string [ ] BasicFilters
@@ -27,16 +29,19 @@ public static string[] BasicFilters
2729
2830 // layout:
2931 private readonly float PropertyMinWidth = 40 ;
30- private readonly float PropertySpace = 5 ;
32+ private float PropertySpace = 5 ;
3133 private Vector2 ScrollPosMain = new ( ) ;
3234 private readonly GUILayoutOption [ ] GUIL_StandartOptions = new GUILayoutOption [ ] { GUILayout . MinWidth ( 100 ) , GUILayout . ExpandWidth ( true ) } ;
3335 private readonly GUILayoutOption [ ] GUIL_DefaultOptions = new GUILayoutOption [ ] { GUILayout . MinWidth ( 150 ) , GUILayout . ExpandWidth ( true ) } ;
34-
3536 // data:
3637 private List < List < ScriptableObject > > groupedConfigs ; // Stores ScriptableObjects grouped by their class types in nested lists
3738 private List < Type > selectedTypes = new ( ) ; // Tracks which ScriptableObject types are currently selected for display
3839 private List < Type > availableTypes = new ( ) ; // Holds all unique ScriptableObject types found in the project
3940
41+ //textures:
42+ private Texture2D spaceIcon ;
43+
44+
4045 // window:
4146 [ MenuItem ( "Window/Game Config Editor" ) ]
4247 public static void ShowWindow ( )
@@ -47,14 +52,19 @@ public static void ShowWindow()
4752 private void OnEnable ( )
4853 {
4954 // Initialize the editor by discovering available types and organizing ScriptableObjects accordingly
55+ // Load the saved layout prefs from EditorPrefs
56+ SetSpace ( ) ;
57+
58+ GetIcons ( ) ;
5059 LoadAvailableTypes ( ) ;
5160 GroupScriptableObjectsByType ( ) ;
5261 }
5362
5463 private void OnGUI ( )
5564 {
5665 EditorGUILayout . BeginHorizontal ( ) ;
57- GUILayout . Label ( "Game Configuration Editor" , EditorStyles . boldLabel ) ;
66+
67+ EditorGUILayout . Space ( ) ;
5868
5969 if ( GUILayout . Button ( "Refresh" , GUILayout . Width ( 80 ) ) )
6070 {
@@ -69,13 +79,33 @@ private void OnGUI()
6979 }
7080 EditorGUILayout . EndHorizontal ( ) ;
7181
82+ EditorGUILayout . Space ( 5 ) ;
83+
84+ EditorGUILayout . BeginHorizontal ( ) ;
7285 // Show a summary of currently selected types or indicate none are selected
7386 GUILayout . Label ( "Selected Config Types: " + ( selectedTypes . Count > 0 ? string . Join ( ", " , selectedTypes . Select ( t => t . Name ) ) : "None" ) , EditorStyles . miniBoldLabel ) ;
7487 if ( groupedConfigs == null || groupedConfigs . Count == 0 )
7588 {
7689 GUILayout . Label ( "No Configs Loaded" , EditorStyles . boldLabel ) ;
7790 }
7891
92+ GUIContent spaceButton ;
93+ if ( spaceIcon != null )
94+ {
95+ spaceButton = new GUIContent ( spaceIcon , "change space between parameters" ) ;
96+ }
97+ else
98+ {
99+ spaceButton = new GUIContent ( "space" , "change space between parameters" ) ;
100+ }
101+
102+ if ( GUILayout . Button ( spaceButton , GUILayout . Width ( 40 ) ) )
103+ {
104+ SetSpace ( ) ;
105+ }
106+
107+ EditorGUILayout . EndHorizontal ( ) ;
108+
79109 // show configs
80110 ScrollPosMain = EditorGUILayout . BeginScrollView ( ScrollPosMain ) ;
81111 if ( groupedConfigs . Count != 0 )
@@ -97,16 +127,41 @@ private void OnGUI()
97127 }
98128
99129 EditorGUILayout . EndHorizontal ( ) ;
100- EditorGUILayout . BeginHorizontal ( "box" ) ;
101-
102- PutPropertiesForObject ( configGroup ) ;
103130
131+ // table:
132+ EditorGUILayout . BeginHorizontal ( "box" ) ;
133+ PutPropertiesForObject_V ( configGroup ) ;
134+
104135 EditorGUILayout . EndHorizontal ( ) ;
105136 }
106137 }
107138 EditorGUILayout . EndScrollView ( ) ;
108139 }
109140
141+ private void SetSpace ( )
142+ {
143+ float propSpace = EditorPrefs . GetFloat ( PROPERTY_SPACE_PREF , - 2 ) ;
144+ if ( propSpace == - 2 )
145+ {
146+ // If no space is set, use the default value
147+ PropertySpace = 0 ;
148+ EditorPrefs . SetFloat ( PROPERTY_SPACE_PREF , PropertySpace ) ;
149+ }
150+ else
151+ {
152+ // If space is already set, increase it by 1
153+ PropertySpace += 1 ;
154+
155+ // If the space exceeds 5, reset it to 0
156+ if ( PropertySpace > 5 ) PropertySpace = - 1 ;
157+
158+ // Save the new space value
159+ EditorPrefs . SetFloat ( PROPERTY_SPACE_PREF , PropertySpace ) ;
160+
161+ Debug . Log ( "Property Space: " + PropertySpace ) ;
162+ }
163+ }
164+
110165 private void RefreshAll ( )
111166 {
112167 LoadAvailableTypes ( ) ;
@@ -136,6 +191,16 @@ void AddNewSO(Type type)
136191 RefreshAll ( ) ;
137192 }
138193
194+ private void GetIcons ( )
195+ {
196+ spaceIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/space.png" ) ;
197+
198+ if ( spaceIcon == null )
199+ {
200+ Debug . LogError ( "space Icon not found in: Assets/Editor/Editor Windows/Icons/space.png" ) ;
201+ }
202+ }
203+
139204 private void LoadAvailableTypes ( )
140205 {
141206 selectedTypes . Clear ( ) ;
@@ -172,7 +237,11 @@ private void GroupScriptableObjectsByType()
172237 . ToList ( ) ;
173238 }
174239
175- private void PutPropertiesForObject < T > ( List < T > Configs ) where T : ScriptableObject
240+
241+ /// <summary>
242+ /// create a vertival table for the properties of the object
243+ /// </summary>
244+ private void PutPropertiesForObject_V < T > ( List < T > Configs ) where T : ScriptableObject
176245 {
177246 try
178247 {
0 commit comments