@@ -43,26 +43,33 @@ public static string[] BasicFilters
4343 private List < Type > selectedTypes = new ( ) ; // Tracks which ScriptableObject types are currently selected for display
4444 private List < Type > availableTypes = new ( ) ; // Holds all unique ScriptableObject types found in the project
4545
46+ // rename operation:
47+ bool isRenaming = false ;
48+ ScriptableObject ObjectToRename = null ;
49+ string renameText = "" ;
50+
4651 // textures:
4752 private Texture2D spaceIcon ;
4853 private Texture2D orientationIcon ;
4954 private Texture2D ConfigOptionsIcon ;
5055 private Texture2D addConfigIcon ;
5156 private Texture2D refreshIcon ;
5257 private Texture2D filtersIcon ;
58+ private Texture2D checkIcon ;
5359
5460 // Buttons Styles:
5561 GUIContent spaceButton ;
5662 GUIContent orientationButton ;
5763 GUIContent refreshButton ;
5864 GUIContent filtersButton ;
65+ GUIContent checkButton ;
5966 // create config button styles:
6067 GUIContent AddConfigButton ;
6168 GUILayoutOption [ ] AddConfigButtonOptions ;
6269 GUIStyle buttonStyle ;
6370 // delete config button styles:
6471 GUIContent ConfigOptionsButton ;
65- GUILayoutOption [ ] ConfigOoptionsButtonOptions ;
72+ GUILayoutOption [ ] ConfigOptionsButtonOptions ;
6673
6774 // label styles:
6875 GUIStyle centeredLabelStyle ;
@@ -144,6 +151,15 @@ private void SetupButtonStyles()
144151 {
145152 filtersButton = new GUIContent ( "filters" , "filters" ) ;
146153 }
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+ }
147163
148164 // 'create config' button styles
149165 if ( addConfigIcon != null )
@@ -157,16 +173,16 @@ private void SetupButtonStyles()
157173 AddConfigButtonOptions = new GUILayoutOption [ ] { GUILayout . Width ( 65 ) } ;
158174 }
159175
160- // 'delete config ' button styles
176+ // 'Config Options ' button styles
161177 if ( ConfigOptionsIcon != null )
162178 {
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 ) } ;
165181 }
166182 else
167183 {
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 ) } ;
170186 }
171187 }
172188
@@ -334,6 +350,7 @@ private void LoadIcons()
334350 addConfigIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/add file.png" ) ;
335351 refreshIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/refresh.png" ) ;
336352 filtersIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/filter.png" ) ;
353+ checkIcon = AssetDatabase . LoadAssetAtPath < Texture2D > ( "Assets/Editor/Editor Windows/Icons/check.png" ) ;
337354
338355 if ( spaceIcon == null )
339356 {
@@ -359,6 +376,10 @@ private void LoadIcons()
359376 {
360377 Debug . LogError ( "filters Icon not found in: Assets/Editor/Editor Windows/Icons/filter.png" ) ;
361378 }
379+ if ( checkIcon == null )
380+ {
381+ Debug . LogError ( "check Icon not found in: Assets/Editor/Editor Windows/Icons/check.png" ) ;
382+ }
362383 }
363384
364385 private void LoadAvailableTypes ( )
@@ -504,7 +525,7 @@ private void OptionsButton<T>(T Config) where T : ScriptableObject
504525 buttonStyle . imagePosition = ImagePosition . ImageOnly ;
505526 }
506527
507- if ( GUILayout . Button ( ConfigOptionsButton , buttonStyle , ConfigOoptionsButtonOptions ) )
528+ if ( GUILayout . Button ( ConfigOptionsButton , buttonStyle , ConfigOptionsButtonOptions ) )
508529 {
509530 ShowOptionsMenu ( Config ) ;
510531 }
@@ -515,7 +536,7 @@ private void ShowOptionsMenu<T>(T Config) where T : ScriptableObject
515536 GenericMenu menu = new GenericMenu ( ) ;
516537
517538 menu . AddItem ( new GUIContent ( "Delete Config" ) , false , ( ) => DeleteConfig ( Config ) ) ;
518-
539+ menu . AddItem ( new GUIContent ( "Rename Config" ) , false , ( ) => { isRenaming = true ; ObjectToRename = Config ; renameText = "" ; } ) ;
519540 menu . AddSeparator ( "" ) ;
520541 menu . AddItem ( new GUIContent ( "Show In Project Folder" ) , false , ( ) => ShowInProjectFolders ( Config ) ) ;
521542 menu . ShowAsContext ( ) ;
@@ -575,8 +596,60 @@ private void PutPropertiesForObject_H<T>(List<T> Configs) where T : ScriptableOb
575596
576597 // Display the file name for the asset
577598 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+ }
579618
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+
580653 // Display a delete button for the asset
581654 OptionsButton ( Config ) ;
582655 GUILayout . Space ( 3 ) ;
@@ -653,5 +726,13 @@ public static float CalculatePropertyHeight<T>(List<T> configs, SerializedProper
653726 return maxHeight ;
654727 }
655728
729+ void OnLostFocus ( )
730+ {
731+ isRenaming = false ;
732+ ObjectToRename = null ;
733+ renameText = "" ;
734+ GUI . FocusControl ( null ) ;
735+ }
736+
656737 }
657738}
0 commit comments