Skip to content

Commit 8e59e04

Browse files
[Editor] Improved handling of list/array elements;
[Editor] Disable clearing thumbnails on folder change; [Editor] Asset Picker attempts to use thumbnails if available;
1 parent 1d1d628 commit 8e59e04

File tree

5 files changed

+127
-95
lines changed

5 files changed

+127
-95
lines changed

Engine/Core/Serialization/Serializer/Serializers/StapleTypesSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public object SerializeField(object instance, Type type, FieldInfo field, Type f
162162
}
163163

164164
break;
165-
}
165+
}
166166

167167
return null;
168168
}

Engine/Editor/Editors/Editor.cs

Lines changed: 94 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -231,47 +231,50 @@ private void PropertyInspector(Type type, string name, string IDSuffix, Func<obj
231231
{
232232
if (getter() is IList list)
233233
{
234-
EditorGUI.Label(name);
235-
236-
EditorGUI.SameLine();
237-
238234
var changed = false;
239235

240-
EditorGUI.Button("+", $"{name}Add{IDSuffix}", () =>
236+
EditorGUI.TreeNode(name, $"{name}Node{IDSuffix}", false, () =>
241237
{
242-
changed = true;
238+
ImGui.BeginGroup();
243239

244-
list.Add(listType.IsValueType ? Activator.CreateInstance(listType) : null);
245-
});
240+
for (var i = 0; i < list.Count; i++)
241+
{
242+
var entry = list[i];
246243

247-
ImGui.BeginGroup();
244+
EditorGUI.Label($"{name} {i + 1}");
248245

249-
for (var i = 0; i < list.Count; i++)
250-
{
251-
var entry = list[i];
246+
var result = EditorGUI.ObjectPicker(listType, "", entry, $"{name} {i} {IDSuffix}");
252247

253-
EditorGUI.Label($"{name} {i + 1}");
248+
if (result != entry)
249+
{
250+
changed = true;
254251

255-
var result = EditorGUI.ObjectPicker(listType, "", entry, $"{name} {i} {IDSuffix}");
252+
list[i] = result;
253+
}
256254

257-
if (result != entry)
258-
{
259-
changed = true;
255+
EditorGUI.SameLine();
256+
257+
EditorGUI.Button("-", $"{name}Remove{i}{IDSuffix}", () =>
258+
{
259+
changed = true;
260260

261-
list[i] = result;
261+
list.RemoveAt(i);
262+
});
262263
}
263264

265+
ImGui.EndGroup();
266+
267+
}, null, () =>
268+
{
264269
EditorGUI.SameLine();
265270

266-
EditorGUI.Button("-", $"{name}Remove{i}{IDSuffix}", () =>
271+
EditorGUI.Button("+", $"{name}Add{IDSuffix}", () =>
267272
{
268273
changed = true;
269274

270-
list.RemoveAt(i);
275+
list.Add(listType.IsValueType ? Activator.CreateInstance(listType) : null);
271276
});
272-
}
273-
274-
ImGui.EndGroup();
277+
});
275278

276279
if (changed)
277280
{
@@ -283,56 +286,59 @@ private void PropertyInspector(Type type, string name, string IDSuffix, Func<obj
283286
{
284287
if (getter() is IList list)
285288
{
286-
EditorGUI.Label(name);
287-
288-
EditorGUI.SameLine();
289-
290289
var changed = false;
291290

292-
EditorGUI.Button("+", $"{name}Add{IDSuffix}", () =>
291+
EditorGUI.TreeNode(name, $"{name}Node{IDSuffix}", false, () =>
293292
{
294-
changed = true;
293+
ImGui.BeginGroup();
295294

296-
list.Add(listType.IsValueType ? Activator.CreateInstance(listType) : null);
297-
});
295+
for (var i = 0; i < list.Count; i++)
296+
{
297+
var entry = list[i];
298298

299-
ImGui.BeginGroup();
299+
PropertyInspector(listType, "", $"{name}{i}{IDSuffix}", () => entry,
300+
(value) =>
301+
{
302+
if (value != entry)
303+
{
304+
changed = true;
305+
306+
list[i] = value;
307+
}
308+
},
309+
(attribute) =>
310+
{
311+
if (attribute.IsSubclassOf(typeof(Attribute)))
312+
{
313+
return listType.GetCustomAttribute(attribute);
314+
}
300315

301-
for (var i = 0; i < list.Count; i++)
302-
{
303-
var entry = list[i];
316+
return null;
317+
});
304318

305-
PropertyInspector(listType, "", $"{name}{i}{IDSuffix}", () => entry,
306-
(value) =>
307-
{
308-
if (value != entry)
309-
{
310-
changed = true;
319+
EditorGUI.SameLine();
311320

312-
list[i] = value;
313-
}
314-
},
315-
(attribute) =>
321+
EditorGUI.Button("-", $"{name}Remove{i}{IDSuffix}", () =>
316322
{
317-
if (attribute.IsSubclassOf(typeof(Attribute)))
318-
{
319-
return listType.GetCustomAttribute(attribute);
320-
}
323+
changed = true;
321324

322-
return null;
325+
list.RemoveAt(i);
323326
});
327+
}
324328

329+
ImGui.EndGroup();
330+
}, null,
331+
() =>
332+
{
325333
EditorGUI.SameLine();
326334

327-
EditorGUI.Button("-", $"{name}Remove{i}{IDSuffix}", () =>
335+
EditorGUI.Button("+", $"{name}Add{IDSuffix}", () =>
328336
{
329337
changed = true;
330338

331-
list.RemoveAt(i);
339+
list.Add(listType.IsValueType ? Activator.CreateInstance(listType) : null);
332340
});
333-
}
334-
335-
ImGui.EndGroup();
341+
});
336342

337343
if (changed)
338344
{
@@ -344,40 +350,44 @@ private void PropertyInspector(Type type, string name, string IDSuffix, Func<obj
344350
{
345351
if (getter() is IList list)
346352
{
347-
EditorGUI.Label(name);
348-
349-
EditorGUI.SameLine();
350-
351353
var changed = false;
352354

353-
EditorGUI.Button("+", $"{name}Add{IDSuffix}", () =>
355+
EditorGUI.TreeNode(name, $"{name}Node{IDSuffix}", false, () =>
354356
{
355-
changed = true;
356357

357-
list.Add(Activator.CreateInstance(listType));
358-
});
358+
ImGui.BeginGroup();
359359

360-
ImGui.BeginGroup();
360+
for (var i = 0; i < list.Count; i++)
361+
{
362+
var entry = list[i];
361363

362-
for (var i = 0; i < list.Count; i++)
363-
{
364-
var entry = list[i];
364+
FieldInspector(entry, name, $"{name}{i}{IDSuffix}", true);
365365

366-
FieldInspector(entry, name, $"{name}{i}{IDSuffix}", true);
366+
list[i] = entry;
367+
368+
EditorGUI.SameLine();
369+
370+
EditorGUI.Button("-", $"{name}Remove{i}{IDSuffix}", () =>
371+
{
372+
changed = true;
367373

368-
list[i] = entry;
374+
list.RemoveAt(i);
375+
});
376+
}
369377

378+
ImGui.EndGroup();
379+
}, null,
380+
() =>
381+
{
370382
EditorGUI.SameLine();
371383

372-
EditorGUI.Button("-", $"{name}Remove{i}{IDSuffix}", () =>
384+
EditorGUI.Button("+", $"{name}Add{IDSuffix}", () =>
373385
{
374386
changed = true;
375387

376-
list.RemoveAt(i);
388+
list.Add(Activator.CreateInstance(listType));
377389
});
378-
}
379-
380-
ImGui.EndGroup();
390+
});
381391

382392
if (changed)
383393
{
@@ -851,6 +861,16 @@ private void PropertyInspector(Type type, string name, string IDSuffix, Func<obj
851861

852862
break;
853863

864+
case Type t when t == typeof(Sprite):
865+
866+
{
867+
var value = (Sprite)getter();
868+
869+
setter(EditorGUI.SpritePicker(name, value, IDSuffix));
870+
}
871+
872+
break;
873+
854874
case Type t when t == typeof(Entity):
855875

856876
{

Engine/Editor/ProjectBrowser/ProjectBrowser.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,6 @@ public void UpdateCurrentContentNodes(List<ProjectBrowserNode> nodes)
340340
{
341341
currentContentBrowserNodes.Clear();
342342

343-
if(nodes != projectBrowserNodes)
344-
{
345-
ThumbnailCache.Clear();
346-
}
347-
348343
foreach (var node in nodes)
349344
{
350345
if (node.path.EndsWith(".meta"))

Engine/Editor/Windows/AssetPickerWindow.cs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,24 @@ internal class AssetPickerWindow : EditorWindow
1515
public AppPlatform currentPlatform;
1616
public string basePath;
1717

18+
private ProjectBrowserNode[] validItems = [];
19+
private List<ImGuiUtils.ContentGridItem> gridItems = [];
20+
1821
public AssetPickerWindow()
1922
{
2023
windowFlags = EditorWindowFlags.Centered;
2124

2225
windowType = EditorWindowType.Popup;
2326
}
2427

25-
public override void OnGUI()
28+
private void Refresh()
2629
{
27-
string newValue = assetPickerSearch;
28-
29-
assetPickerSearch = EditorGUI.TextField("Search", "AssetPickerSearch", newValue);
30-
3130
var validItems = new List<ProjectBrowserNode>
3231
{
3332
null
3433
};
3534

36-
foreach(var asset in AssetDatabase.assets)
35+
foreach (var asset in AssetDatabase.assets)
3736
{
3837
if ((assetPickerSearch?.Length ?? 0) > 0 &&
3938
asset.name.Contains(assetPickerSearch, StringComparison.InvariantCultureIgnoreCase) == false)
@@ -53,15 +52,36 @@ public override void OnGUI()
5352
}
5453
}
5554

56-
projectBrowser.editorResources.TryGetValue("FileIcon", out var texture);
55+
this.validItems = validItems.ToArray();
5756

58-
var gridItems = validItems
57+
projectBrowser.editorResources.TryGetValue("FileIcon", out var fileIcon);
58+
59+
gridItems = validItems
5960
.Select(x => new ImGuiUtils.ContentGridItem()
6061
{
6162
name = x?.name ?? "(None)",
62-
texture = texture,
63-
ensureValidTexture = (_) => texture,
63+
ensureValidTexture = (texture) =>
64+
{
65+
if (x != null && ((texture?.Disposed ?? true) || ThumbnailCache.HasCachedThumbnail(x.path)))
66+
{
67+
return ThumbnailCache.GetThumbnail(x.path) ?? projectBrowser.GetResourceIcon(ProjectBrowser.ResourceTypeForExtension(x.extension));
68+
}
69+
70+
return texture ?? fileIcon;
71+
},
6472
}).ToList();
73+
}
74+
75+
public override void OnGUI()
76+
{
77+
string newValue = assetPickerSearch;
78+
79+
assetPickerSearch = EditorGUI.TextField("Search", "AssetPickerSearch", newValue);
80+
81+
if (newValue != assetPickerSearch || validItems.Length == 0)
82+
{
83+
Refresh();
84+
}
6585

6686
ImGuiUtils.ContentGrid(gridItems, ProjectBrowser.contentPanelPadding, ProjectBrowser.contentPanelThumbnailSize,
6787
null, false,
@@ -113,6 +133,8 @@ public override void OnGUI()
113133
{
114134
case ProjectBrowserResourceType.Texture:
115135

136+
Texture texture = null;
137+
116138
try
117139
{
118140
texture = ResourceManager.instance.LoadTexture(guid);

Test Project/Assets/Scripts/Editor/TestWindow.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ public TestWindow()
2020

2121
public override void OnGUI()
2222
{
23-
EditorGUI.Button("X", "Close", () =>
24-
{
25-
Close();
26-
});
27-
2823
EditorGUI.Label("Test Window from game!");
2924
}
3025
}

0 commit comments

Comments
 (0)