@@ -43,26 +43,33 @@ public static string[] BasicFilters
43
43
private List < Type > selectedTypes = new ( ) ; // Tracks which ScriptableObject types are currently selected for display
44
44
private List < Type > availableTypes = new ( ) ; // Holds all unique ScriptableObject types found in the project
45
45
46
+ // rename operation:
47
+ bool isRenaming = false ;
48
+ ScriptableObject ObjectToRename = null ;
49
+ string renameText = "" ;
50
+
46
51
// textures:
47
52
private Texture2D spaceIcon ;
48
53
private Texture2D orientationIcon ;
49
54
private Texture2D ConfigOptionsIcon ;
50
55
private Texture2D addConfigIcon ;
51
56
private Texture2D refreshIcon ;
52
57
private Texture2D filtersIcon ;
58
+ private Texture2D checkIcon ;
53
59
54
60
// Buttons Styles:
55
61
GUIContent spaceButton ;
56
62
GUIContent orientationButton ;
57
63
GUIContent refreshButton ;
58
64
GUIContent filtersButton ;
65
+ GUIContent checkButton ;
59
66
// create config button styles:
60
67
GUIContent AddConfigButton ;
61
68
GUILayoutOption [ ] AddConfigButtonOptions ;
62
69
GUIStyle buttonStyle ;
63
70
// delete config button styles:
64
71
GUIContent ConfigOptionsButton ;
65
- GUILayoutOption [ ] ConfigOoptionsButtonOptions ;
72
+ GUILayoutOption [ ] ConfigOptionsButtonOptions ;
66
73
67
74
// label styles:
68
75
GUIStyle centeredLabelStyle ;
@@ -144,6 +151,15 @@ private void SetupButtonStyles()
144
151
{
145
152
filtersButton = new GUIContent ( "filters" , "filters" ) ;
146
153
}
154
+ // GUI content for check button
155
+ if ( checkIcon != null )
156
+ {
157
+ checkButton = new GUIContent ( checkIcon , "check" ) ;
158
+ }
159
+ else
160
+ {
161
+ checkButton = new GUIContent ( "ok" , "check" ) ;
162
+ }
147
163
148
164
// 'create config' button styles
149
165
if ( addConfigIcon != null )
@@ -157,16 +173,16 @@ private void SetupButtonStyles()
157
173
AddConfigButtonOptions = new GUILayoutOption [ ] { GUILayout . Width ( 65 ) } ;
158
174
}
159
175
160
- // 'delete config ' button styles
176
+ // 'Config Options ' button styles
161
177
if ( ConfigOptionsIcon != null )
162
178
{
163
- ConfigOptionsButton = new GUIContent ( ConfigOptionsIcon , "delete config permanently " ) ;
164
- ConfigOoptionsButtonOptions = new GUILayoutOption [ ] { GUILayout . Height ( 20 ) , GUILayout . Width ( 20 ) } ;
179
+ ConfigOptionsButton = new GUIContent ( ConfigOptionsIcon , "Options " ) ;
180
+ ConfigOptionsButtonOptions = new GUILayoutOption [ ] { GUILayout . Height ( 20 ) , GUILayout . Width ( 20 ) } ;
165
181
}
166
182
else
167
183
{
168
- ConfigOptionsButton = new GUIContent ( "del " , "delete config permanently " ) ;
169
- ConfigOoptionsButtonOptions = new GUILayoutOption [ ] { GUILayout . Width ( 30 ) } ;
184
+ ConfigOptionsButton = new GUIContent ( "opt " , "Options " ) ;
185
+ ConfigOptionsButtonOptions = new GUILayoutOption [ ] { GUILayout . Width ( 30 ) } ;
170
186
}
171
187
}
172
188
@@ -334,6 +350,7 @@ private void LoadIcons()
334
350
addConfigIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/add file.png" ) ;
335
351
refreshIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/refresh.png" ) ;
336
352
filtersIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/filter.png" ) ;
353
+ checkIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/check.png" ) ;
337
354
338
355
if ( spaceIcon == null )
339
356
{
@@ -359,6 +376,10 @@ private void LoadIcons()
359
376
{
360
377
Debug . LogError ( "filters Icon not found in: Assets/Editor/Editor Windows/Icons/filter.png" ) ;
361
378
}
379
+ if ( checkIcon == null )
380
+ {
381
+ Debug . LogError ( "check Icon not found in: Assets/Editor/Editor Windows/Icons/check.png" ) ;
382
+ }
362
383
}
363
384
364
385
private void LoadAvailableTypes ( )
@@ -504,7 +525,7 @@ private void OptionsButton<T>(T Config) where T : ScriptableObject
504
525
buttonStyle . imagePosition = ImagePosition . ImageOnly ;
505
526
}
506
527
507
- if ( GUILayout . Button ( ConfigOptionsButton , buttonStyle , ConfigOoptionsButtonOptions ) )
528
+ if ( GUILayout . Button ( ConfigOptionsButton , buttonStyle , ConfigOptionsButtonOptions ) )
508
529
{
509
530
ShowOptionsMenu ( Config ) ;
510
531
}
@@ -515,7 +536,7 @@ private void ShowOptionsMenu<T>(T Config) where T : ScriptableObject
515
536
GenericMenu menu = new GenericMenu ( ) ;
516
537
517
538
menu . AddItem ( new GUIContent ( "Delete Config" ) , false , ( ) => DeleteConfig ( Config ) ) ;
518
-
539
+ menu . AddItem ( new GUIContent ( "Rename Config" ) , false , ( ) => { isRenaming = true ; ObjectToRename = Config ; renameText = "" ; } ) ;
519
540
menu . AddSeparator ( "" ) ;
520
541
menu . AddItem ( new GUIContent ( "Show In Project Folder" ) , false , ( ) => ShowInProjectFolders ( Config ) ) ;
521
542
menu . ShowAsContext ( ) ;
@@ -575,8 +596,60 @@ private void PutPropertiesForObject_H<T>(List<T> Configs) where T : ScriptableOb
575
596
576
597
// Display the file name for the asset
577
598
GUIContent propertyContent = new GUIContent ( fileName , fileName ) ;
578
- EditorGUILayout . LabelField ( propertyContent , EditorStyles . miniBoldLabel , GUILayout . Width ( 120 ) ) ;
599
+
600
+
601
+ Rect elementRect = GUILayoutUtility . GetRect ( 120 , 120 , 18 , 18 , GUILayout . Width ( 120 ) ) ;
602
+
603
+ if ( isRenaming && ObjectToRename != null && ObjectToRename == Config )
604
+ {
605
+ GUI . SetNextControlName ( "RenameField" ) ;
606
+
607
+ // Display a text field for renaming the asset.if renameText is empty, show the file name until the user types something
608
+ renameText = EditorGUI . TextField ( elementRect , renameText == "" ? fileName : renameText ) ;
609
+
610
+ Event e = Event . current ;
611
+
612
+ if ( isRenaming && e . type == EventType . MouseDown && ! elementRect . Contains ( e . mousePosition ) )
613
+ {
614
+ isRenaming = false ;
615
+ GUI . FocusControl ( null ) ;
616
+ e . Use ( ) ; // Olayý tüketiyoruz
617
+ }
579
618
619
+ if ( GUILayout . Button ( checkButton , buttonStyle , ConfigOptionsButtonOptions ) )
620
+ {
621
+ AssetDatabase . RenameAsset ( filePath , renameText ) ;
622
+ AssetDatabase . SaveAssets ( ) ;
623
+ isRenaming = false ;
624
+ renameText = "" ;
625
+ ObjectToRename = null ;
626
+ GUI . FocusControl ( null ) ;
627
+ }
628
+
629
+ if ( Event . current . keyCode == KeyCode . Return || Event . current . keyCode == KeyCode . KeypadEnter )
630
+ {
631
+ AssetDatabase . RenameAsset ( filePath , renameText ) ;
632
+ AssetDatabase . SaveAssets ( ) ;
633
+ isRenaming = false ;
634
+ renameText = "" ;
635
+ ObjectToRename = null ;
636
+ GUI . FocusControl ( null ) ;
637
+ }
638
+ else if ( Event . current . keyCode == KeyCode . Escape )
639
+ {
640
+ renameText = "" ;
641
+ isRenaming = false ;
642
+ ObjectToRename = null ;
643
+ GUI . FocusControl ( null ) ;
644
+ }
645
+
646
+ EditorGUI . FocusTextInControl ( "RenameField" ) ;
647
+ }
648
+ else
649
+ {
650
+ EditorGUI . LabelField ( elementRect , propertyContent , EditorStyles . miniBoldLabel ) ;
651
+ }
652
+
580
653
// Display a delete button for the asset
581
654
OptionsButton ( Config ) ;
582
655
GUILayout . Space ( 3 ) ;
@@ -653,5 +726,13 @@ public static float CalculatePropertyHeight<T>(List<T> configs, SerializedProper
653
726
return maxHeight ;
654
727
}
655
728
729
+ void OnLostFocus ( )
730
+ {
731
+ isRenaming = false ;
732
+ ObjectToRename = null ;
733
+ renameText = "" ;
734
+ GUI . FocusControl ( null ) ;
735
+ }
736
+
656
737
}
657
738
}
0 commit comments