Skip to content

Commit ec2b6e2

Browse files
committed
a button added to set space between parameters
1 parent 6d69f65 commit ec2b6e2

File tree

6 files changed

+218
-12
lines changed

6 files changed

+218
-12
lines changed

Assets/Editor/Editor Windows/Icons.meta

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

Assets/Editor/Editor Windows/Icons/space.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: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
public 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
{

Assets/Resources/ScriptableObjects/Test2Config 1.asset

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,4 @@ MonoBehaviour:
1313
m_Name: Test2Config 1
1414
m_EditorClassIdentifier:
1515
numberArray:
16-
gameObjectArray:
17-
- {fileID: 0}
18-
- {fileID: 0}
19-
- {fileID: 0}
16+
gameObjectArray: []

Assets/Resources/ScriptableObjects/Test2Config.asset

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: 2cac81c9ac410e441bde07e00491a572, type: 3}
1313
m_Name: Test2Config
1414
m_EditorClassIdentifier:
15-
numberArray: 01000000020000000300000004000000
15+
numberArray:
1616
gameObjectArray:
1717
- {fileID: 0}
1818
- {fileID: 0}
19+
- {fileID: 0}
20+
- {fileID: 0}
21+
- {fileID: 0}
22+
- {fileID: 0}
23+
- {fileID: 0}

0 commit comments

Comments
 (0)