@@ -14,48 +14,44 @@ public class ScriptableObjectEditorWindow : EditorWindow
1414 private GUILayoutOption [ ] GUIL_DefaultOptions = new GUILayoutOption [ ] { GUILayout . MinWidth ( 150 ) , GUILayout . ExpandWidth ( true ) } ;
1515
1616 // data:
17- private List < List < ScriptableObject > > groupedConfigs ; // Her sýnýf türü için iç içe liste
18- private List < Type > selectedTypes = new List < Type > ( ) ; // Seçilen ScriptableObject tipleri
19- private List < Type > availableTypes = new List < Type > ( ) ; // Kullanýlabilir ScriptableObject tipleri
17+ private List < List < ScriptableObject > > groupedConfigs ; // Stores ScriptableObjects grouped by their class types in nested lists
18+ private List < Type > selectedTypes = new List < Type > ( ) ; // Tracks which ScriptableObject types are currently selected for display
19+ private List < Type > availableTypes = new List < Type > ( ) ; // Holds all unique ScriptableObject types found in the project
2020
21- [ MenuItem ( "Window/game Config Editor" ) ]
21+ [ MenuItem ( "Window/Game Config Editor" ) ]
2222 public static void ShowWindow ( )
2323 {
24- GetWindow < ScriptableObjectEditorWindow > ( "game Config Editor" ) ;
24+ GetWindow < ScriptableObjectEditorWindow > ( "Game Config Editor" ) ;
2525 }
26+
2627 private void OnEnable ( )
2728 {
28- LoadAvailableTypes ( ) ; // Kullanýlabilir ScriptableObject tiplerini yükle
29- GroupScriptableObjectsByType ( ) ; // ScriptableObject'leri tiplerine göre grupla
29+ // Initialize the editor by discovering available types and organizing ScriptableObjects accordingly
30+ LoadAvailableTypes ( ) ;
31+ GroupScriptableObjectsByType ( ) ;
3032 }
3133
3234 private void OnGUI ( )
3335 {
34-
35- // Baþlýk kýsmý ve ayarlar menüsü
3636 EditorGUILayout . BeginHorizontal ( ) ;
3737 GUILayout . Label ( "Game Configuration Editor" , EditorStyles . boldLabel ) ;
3838
39- // Refresh butonu
4039 if ( GUILayout . Button ( "Refresh" , GUILayout . Width ( 80 ) ) )
4140 {
4241 LoadAvailableTypes ( ) ;
4342 GroupScriptableObjectsByType ( ) ;
4443 }
4544
46- // Config tipi seçim menüsü
45+ // Display a popup window at the mouse position for type selection
4746 if ( GUILayout . Button ( "Filter" , GUILayout . Width ( 80 ) ) )
4847 {
4948 Vector2 mousePosition = Event . current . mousePosition ;
50- // Toggle seçeneklerini göstermek için özel Popup aç
5149 PopupWindow . Show ( new Rect ( mousePosition . x , mousePosition . y + 20 , 0 , 0 ) , new ConfigTypeSelectionPopup ( selectedTypes , GroupScriptableObjectsByType , availableTypes ) ) ;
5250 }
5351 EditorGUILayout . EndHorizontal ( ) ;
5452
55-
56- // Seçilen tipleri göster
53+ // Show a summary of currently selected types or indicate none are selected
5754 GUILayout . Label ( "Selected Config Types: " + ( selectedTypes . Count > 0 ? string . Join ( ", " , selectedTypes . Select ( t => t . Name ) ) : "None" ) , EditorStyles . miniBoldLabel ) ;
58-
5955 if ( groupedConfigs == null || groupedConfigs . Count == 0 )
6056 {
6157 GUILayout . Label ( "No Configs Loaded" , EditorStyles . boldLabel ) ;
@@ -64,44 +60,44 @@ private void OnGUI()
6460 ScrollPos = EditorGUILayout . BeginScrollView ( ScrollPos ) ;
6561 if ( groupedConfigs . Count != 0 )
6662 {
67-
6863 foreach ( var configGroup in groupedConfigs )
6964 {
70- // Eðer grup boþsa veya seçilen tiplerle eþleþmiyorsa devam et
65+ // Only display groups that match the selected types or if no specific types are filtered
7166 if ( selectedTypes . Count == 0 || ! selectedTypes . Contains ( configGroup [ 0 ] . GetType ( ) ) )
7267 continue ;
7368
74- GUILayout . Label ( configGroup [ 0 ] . GetType ( ) . Name , EditorStyles . boldLabel ) ; // Grup baþlýðý olarak tip ismi göster
69+ GUILayout . Label ( configGroup [ 0 ] . GetType ( ) . Name , EditorStyles . boldLabel ) ; // Display the type name as a section header
7570
7671 EditorGUILayout . BeginHorizontal ( "box" ) ;
7772
7873 PutPropertiesForObject ( configGroup ) ;
7974
8075 EditorGUILayout . EndHorizontal ( ) ;
81-
8276 }
8377 }
84- //scrollView sonu
78+ // Close the scrollable area
8579 EditorGUILayout . EndScrollView ( ) ;
8680 }
8781
8882 private void LoadAvailableTypes ( )
8983 {
84+ // Scan the "ScriptableObjects" folder to find all unique ScriptableObject types
9085 availableTypes = Resources . LoadAll < ScriptableObject > ( "ScriptableObjects" ) . Select ( t => t . GetType ( ) ) . Distinct ( ) . ToList ( ) ;
9186 selectedTypes . Clear ( ) ;
87+
9288 selectedTypes . AddRange ( availableTypes ) ;
9389 }
9490
9591 private void GroupScriptableObjectsByType ( )
9692 {
97- // ScriptableObject'leri belirli bir klasörden yükle (örneðin Resources) ve sýnýf türlerine göre gruplandýr
93+ // Fetch all ScriptableObjects from a designated folder and organize them into groups based on their class types
9894 var configs = Resources . LoadAll < ScriptableObject > ( "" ) . ToList ( ) ;
9995
10096 groupedConfigs = configs
10197 . GroupBy ( c => c . GetType ( ) )
102- . Where ( g => selectedTypes . Count == 0 || selectedTypes . Contains ( g . Key ) ) // Seçilen tipleri filtrele
103- . Select ( g => g . ToList ( ) ) // Her tip için bir alt liste oluþtur
104- . ToList ( ) ;
98+ . Where ( g => selectedTypes . Count == 0 || selectedTypes . Contains ( g . Key ) ) // Only include groups matching the current type filter
99+ . Select ( g => g . ToList ( ) ) // Convert each group into a list of ScriptableObjects
100+ . ToList ( ) ;
105101 }
106102
107103 private void PutPropertiesForObject < T > ( List < T > Configs ) where T : ScriptableObject
@@ -111,26 +107,28 @@ private void PutPropertiesForObject<T>(List<T> Configs) where T : ScriptableObje
111107 EditorGUILayout . BeginVertical ( "box" ) ;
112108 try
113109 {
114- EditorGUILayout . LabelField ( "" , GUILayout . MinWidth ( PropertyMinWidth ) ) ; // to show file names properly this should have an empty label
110+ // An empty label to align property names properly in the UI
111+ EditorGUILayout . LabelField ( "" , GUILayout . MinWidth ( PropertyMinWidth ) ) ;
115112
116- // SerializedObject ve SerializedProperty kullan
113+ // Iterate through the properties of the first ScriptableObject to display their names
117114 SerializedObject serializedObject = new SerializedObject ( Configs [ 0 ] ) ;
118115 SerializedProperty property = serializedObject . GetIterator ( ) ;
119116
120117 bool ShouldNext = property . NextVisible ( true ) ;
121118 while ( ShouldNext )
122119 {
123- if ( property . propertyType != SerializedPropertyType . ArraySize && property . name != "m_Script" && property . name != "data" ) // m_Script'i atla
120+ if ( property . propertyType != SerializedPropertyType . ArraySize && property . name != "m_Script" && property . name != "data" ) // Exclude internal Unity fields and arrays
124121 {
125- // Deðiþken ismini yazdýr
122+ // Show the name of each property as a label
126123 EditorGUILayout . LabelField ( property . name , GUILayout . MinWidth ( PropertyMinWidth ) ) ;
127124 GUILayout . Space ( PropertySpace ) ;
128125 }
129- ShouldNext = property . NextVisible ( false ) ; // to not include childrens
126+ ShouldNext = property . NextVisible ( false ) ; // Move to the next property, skipping nested children
130127 }
131128 }
132129 catch
133130 {
131+ // If an error occurs, refresh the type list and regroup the objects
134132 LoadAvailableTypes ( ) ;
135133 GroupScriptableObjectsByType ( ) ;
136134 }
@@ -141,31 +139,28 @@ private void PutPropertiesForObject<T>(List<T> Configs) where T : ScriptableObje
141139 EditorGUILayout . BeginVertical ( "box" ) ;
142140 try
143141 {
144- // Dosya adýný al
142+ // Retrieve and display the asset's file name without its extension
145143 string filePath = AssetDatabase . GetAssetPath ( Config ) ;
146144 string fileName = System . IO . Path . GetFileNameWithoutExtension ( filePath ) ;
147145 if ( fileName == "" ) throw new System . Exception ( ) ;
148- // Dosya adýný yazdýr
149146 EditorGUILayout . LabelField ( fileName , EditorStyles . miniBoldLabel , GUILayout . MinWidth ( PropertyMinWidth ) ) ;
150147
151148 SerializedObject serializedObject = new SerializedObject ( Config ) ;
152149 SerializedProperty property = serializedObject . GetIterator ( ) ;
153150
154- // Tüm deðiþken isimlerini yazdýr ve uygun alanlarý oluþtur
151+ // Iterate through all properties to create editable fields based on their types
155152 bool ShouldNext = property . NextVisible ( true ) ;
156153 while ( ShouldNext )
157154 {
158- if ( property . propertyType != SerializedPropertyType . ArraySize && property . name != "m_Script" && property . name != "data" ) // m_Script'i atla
155+ if ( property . propertyType != SerializedPropertyType . ArraySize && property . name != "m_Script" && property . name != "data" ) // Skip unwanted properties
159156 {
160- // Deðiþkenin türüne göre uygun alaný oluþtur
157+ // Generate an appropriate UI control based on the property's data type
161158 switch ( property . propertyType )
162159 {
163-
164160 case SerializedPropertyType . String :
165- // Deðiþken adý ile ilgili bir kopya oluþtur
166- string oldStringValue = property . stringValue ;
167- property . stringValue = EditorGUILayout . TextField ( oldStringValue , GUIL_StandartOptions ) ;
168- break ;
161+ string oldStringValue = property . stringValue ;
162+ property . stringValue = EditorGUILayout . TextField ( oldStringValue , GUIL_StandartOptions ) ;
163+ break ;
169164 case SerializedPropertyType . Integer :
170165 int oldIntValue = property . intValue ;
171166 property . intValue = EditorGUILayout . IntField ( oldIntValue , GUIL_StandartOptions ) ;
@@ -184,28 +179,27 @@ private void PutPropertiesForObject<T>(List<T> Configs) where T : ScriptableObje
184179 default :
185180 EditorGUILayout . PropertyField ( property , GUIContent . none , true , GUIL_DefaultOptions ) ;
186181 break ;
187- // Diðer türler için gerekli alanlarý buraya ekleyebilirsin
188-
182+ // Additional cases can be added here to support more property types
189183 }
190184 GUILayout . Space ( PropertySpace ) ;
191185 serializedObject . ApplyModifiedProperties ( ) ;
192186 }
193- ShouldNext = property . NextVisible ( false ) ; // to not include childrens
187+ ShouldNext = property . NextVisible ( false ) ; // Advance to the next property, excluding nested fields
194188 }
195189 property . Reset ( ) ;
196- // Deðiþiklikleri kaydet
197-
198190 }
199191 catch
200192 {
193+ // Handle errors by refreshing the type list and regrouping
201194 LoadAvailableTypes ( ) ;
202195 GroupScriptableObjectsByType ( ) ;
203196 }
204197 EditorGUILayout . EndVertical ( ) ;
205198 }
206199 }
207- catch //(System.Exception e)
200+ catch
208201 {
202+ // Catch any top-level errors and reset the data
209203 LoadAvailableTypes ( ) ;
210204 GroupScriptableObjectsByType ( ) ;
211205 }
@@ -229,7 +223,7 @@ public ConfigTypeSelectionPopup(List<Type> selectedTypes, Action onSelectionChan
229223
230224 public override Vector2 GetWindowSize ( )
231225 {
232- return new Vector2 ( 200 , 500 ) ; // Popup boyutu
226+ return new Vector2 ( 200 , 500 ) ; // Define the dimensions of the popup window
233227 }
234228
235229 public override void OnGUI ( Rect rect )
@@ -238,30 +232,28 @@ public override void OnGUI(Rect rect)
238232
239233 if ( availableTypes . Count > 0 )
240234 {
241-
242235 ScrollPos = EditorGUILayout . BeginScrollView ( ScrollPos ) ;
243236
244- // Her tipi bir Toggle ile gösteriyoruz
237+ // Display each available type with a toggle to enable or disable it
245238 foreach ( var type in availableTypes )
246239 {
247240 bool isSelected = selectedTypes . Contains ( type ) ;
248241 bool toggle = EditorGUILayout . Toggle ( type . Name , isSelected ) ;
249242
250243 if ( toggle && ! isSelected )
251244 {
252- selectedTypes . Add ( type ) ; // Tip seçildi
245+ selectedTypes . Add ( type ) ; // Add the type to the selection list
253246 onSelectionChanged . Invoke ( ) ;
254247 }
255248 else if ( ! toggle && isSelected )
256249 {
257- selectedTypes . Remove ( type ) ; // Tip çýkarýldý
250+ selectedTypes . Remove ( type ) ; // Remove the type from the selection list
258251 onSelectionChanged . Invoke ( ) ;
259252 }
260253 }
261254
262- // ScrollView sonu
255+ // Close the scrollable area within the popup
263256 EditorGUILayout . EndScrollView ( ) ;
264257 }
265258 }
266- }
267-
259+ }
0 commit comments