Skip to content

Commit 1fb78da

Browse files
committed
config rename option added
1 parent 7f4e486 commit 1fb78da

File tree

5 files changed

+218
-10
lines changed

5 files changed

+218
-10
lines changed
273 Bytes
Loading

Assets/Editor/Editor Windows/Icons/check.png.meta

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/Editor Windows/ScriptableObjectEditorWindow.cs

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Assets/Resources/ScriptableObjects/TestConfig 2.asset renamed to Assets/Resources/ScriptableObjects/TestConfig3.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ MonoBehaviour:
1010
m_Enabled: 1
1111
m_EditorHideFlags: 0
1212
m_Script: {fileID: 11500000, guid: b23340d9b453ca740945f54769125bb1, type: 3}
13-
m_Name: TestConfig 2
13+
m_Name: TestConfig3
1414
m_EditorClassIdentifier:
1515
number: 22
1616
value: 0

0 commit comments

Comments
 (0)