Skip to content

Commit 573da0e

Browse files
committed
[v0.3.10] Minor improvements for EntityReceipeEditor
1 parent 1951ce4 commit 573da0e

15 files changed

Lines changed: 102 additions & 22 deletions

Editor/EntityRecipeEditor.cs

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace Depra.Ecs.Hybrid.Editor
1414
[CustomEditor(typeof(EntityRecipe))]
1515
internal sealed class EntityRecipeEditor : UnityEditor.Editor
1616
{
17-
private static void DrawBundlesHeader(Rect rect) => EditorGUI.LabelField(rect, "Component Bundles");
18-
private static void DrawSourcesHeader(Rect rect) => EditorGUI.LabelField(rect, "Component Sources");
19-
2017
private ReorderableList _componentBundles;
2118
private SerializedProperty _componentBundlesProperty;
2219
private ReorderableList _componentSources;
@@ -38,15 +35,14 @@ private void OnEnable()
3835
_componentSources = new ReorderableList(serializedObject, _componentSourcesProperty, true, true, true, true)
3936
{
4037
drawHeaderCallback = DrawSourcesHeader,
41-
drawElementCallback = DrawSourceElement
38+
drawElementCallback = DrawSourceElement,
4239
};
4340
}
4441

4542
public override void OnInspectorGUI()
4643
{
4744
serializedObject.Update();
48-
var recipe = (EntityRecipe)target;
49-
DrawControlButtons(recipe);
45+
DrawControlButtons((EntityRecipe)target);
5046
EditorGUILayout.Space(5);
5147
_componentBundles.DoLayoutList();
5248
_componentSources.DoLayoutList();
@@ -142,13 +138,27 @@ private void DrawBundleElement(Rect rect, int index, bool isActive, bool isFocus
142138
if (componentBundle)
143139
{
144140
var actionRect = new Rect(rect.x + rect.width - 45, rect.y, 45, rect.height);
141+
var pendingOriginalPath = isNested ? GetPendingDeletionPath(componentBundle) : null;
142+
var hasPendingOriginal = !string.IsNullOrEmpty(pendingOriginalPath);
143+
145144
if (!isNested)
146145
{
147146
if (GUI.Button(actionRect, "Nest"))
148147
{
149148
MakeNested(recipe, index);
150149
}
151150
}
151+
else if (hasPendingOriginal)
152+
{
153+
var originalColor = GUI.backgroundColor;
154+
GUI.backgroundColor = new Color(1f, 0.3f, 0.3f);
155+
if (GUI.Button(actionRect, "Del"))
156+
{
157+
DeleteOriginal(componentBundle, pendingOriginalPath);
158+
}
159+
160+
GUI.backgroundColor = originalColor;
161+
}
152162
else
153163
{
154164
if (GUI.Button(actionRect, "Out"))
@@ -172,15 +182,9 @@ private void OnBundleRemoved(ReorderableList list)
172182
var componentBundle = element.objectReferenceValue as ComponentDatabase;
173183
var recipe = (EntityRecipe)target;
174184

175-
Undo.RecordObject(recipe, "Remove Set");
176-
177-
if (componentBundle)
185+
if (componentBundle && IsNestedInAsset(componentBundle, recipe))
178186
{
179-
recipe.Remove(componentBundle);
180-
if (IsNestedInAsset(componentBundle, recipe))
181-
{
182-
Undo.DestroyObjectImmediate(componentBundle);
183-
}
187+
Undo.DestroyObjectImmediate(componentBundle);
184188
}
185189

186190
ReorderableList.defaultBehaviours.DoRemoveButton(list);
@@ -229,6 +233,7 @@ private void MakeAllNested(EntityRecipe recipe, List<ComponentDatabase> bundles)
229233

230234
var newNested = CreateNestedCopy(recipe, componentBundle);
231235
_componentBundlesProperty.GetArrayElementAtIndex(index).objectReferenceValue = newNested;
236+
SavePendingDeletion(newNested, componentBundle);
232237
convertedCount++;
233238
}
234239

@@ -249,12 +254,45 @@ private void MakeNested(EntityRecipe recipe, int index)
249254
Undo.RecordObject(recipe, $"Make Nested: {original.name}");
250255
var newNested = CreateNestedCopy(recipe, original);
251256
_componentBundlesProperty.GetArrayElementAtIndex(index).objectReferenceValue = newNested;
252-
257+
SavePendingDeletion(newNested, original);
253258
serializedObject.ApplyModifiedProperties();
254259
EditorUtility.SetDirty(recipe);
255260
AssetDatabase.SaveAssets();
256261
}
257262

263+
private static void DeleteOriginal(ComponentDatabase nested, string originalPath)
264+
{
265+
if (nested == null || string.IsNullOrEmpty(originalPath))
266+
{
267+
return;
268+
}
269+
270+
if (!File.Exists(originalPath))
271+
{
272+
ClearPendingDeletion(nested);
273+
Debug.LogWarning($"Original file no longer exists: {originalPath}");
274+
return;
275+
}
276+
277+
if (EditorUtility.DisplayDialog(
278+
"Delete Original File",
279+
$"Delete original file?\n\n{originalPath}\n\nThis cannot be undone!",
280+
"Delete",
281+
"Cancel"))
282+
{
283+
if (AssetDatabase.DeleteAsset(originalPath))
284+
{
285+
ClearPendingDeletion(nested);
286+
AssetDatabase.SaveAssets();
287+
Debug.Log($"Deleted original file: {originalPath}");
288+
}
289+
else
290+
{
291+
Debug.LogError($"Failed to delete: {originalPath}");
292+
}
293+
}
294+
}
295+
258296
private static ComponentDatabase CreateNestedCopy(EntityRecipe recipe, ComponentDatabase original)
259297
{
260298
var copy = Instantiate(original);
@@ -320,5 +358,47 @@ private static ComponentDatabase ExtractToNewAsset(ComponentDatabase nested, str
320358

321359
return copy;
322360
}
361+
362+
private static void DrawBundlesHeader(Rect rect) => EditorGUI.LabelField(rect, "Component Bundles");
363+
private static void DrawSourcesHeader(Rect rect) => EditorGUI.LabelField(rect, "Component Sources");
364+
365+
private static string GetSessionStateKey(string nestedGuid) => $"EntityRecipe_PendingDeletion_{nestedGuid}";
366+
367+
private static void SavePendingDeletion(ComponentDatabase nested, ComponentDatabase original)
368+
{
369+
if (!nested || !original)
370+
{
371+
return;
372+
}
373+
374+
var nestedPath = AssetDatabase.GetAssetPath(nested);
375+
var nestedGuid = AssetDatabase.AssetPathToGUID(nestedPath);
376+
var originalPath = AssetDatabase.GetAssetPath(original);
377+
SessionState.SetString(GetSessionStateKey(nestedGuid), originalPath);
378+
}
379+
380+
private static string GetPendingDeletionPath(ComponentDatabase nested)
381+
{
382+
if (nested == null)
383+
{
384+
return null;
385+
}
386+
387+
var nestedPath = AssetDatabase.GetAssetPath(nested);
388+
var nestedGuid = AssetDatabase.AssetPathToGUID(nestedPath);
389+
return SessionState.GetString(GetSessionStateKey(nestedGuid), null);
390+
}
391+
392+
private static void ClearPendingDeletion(ComponentDatabase nested)
393+
{
394+
if (nested == null)
395+
{
396+
return;
397+
}
398+
399+
var nestedPath = AssetDatabase.GetAssetPath(nested);
400+
var nestedGuid = AssetDatabase.AssetPathToGUID(nestedPath);
401+
SessionState.EraseString(GetSessionStateKey(nestedGuid));
402+
}
323403
}
324404
}

Runtime/Components/AuthoringEntityRecipe.cs renamed to Runtime/Entities/AuthoringEntityRecipe.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// © 2023-2026 Depra <n.melnikov@depra.org>
33

4-
using System.Collections.Generic;
54
using System.Runtime.CompilerServices;
65
using UnityEngine;
76
using static Depra.Ecs.Hybrid.RuntimeSceneBakeModule;
File renamed without changes.
File renamed without changes.

Runtime/Entities/ContinuousEntityBakingSystem.cs renamed to Runtime/Module/ContinuousEntityBakingSystem.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// © 2023-2025 Nikolay Melnikov <n.melnikov@depra.org>
2+
// © 2023-2026 Depra <n.melnikov@depra.org>
33

44
using Depra.Ecs.QoL;
55
#if ENABLE_IL2CPP
@@ -14,14 +14,15 @@ namespace Depra.Ecs.Hybrid
1414
#endif
1515
public sealed class ContinuousEntityBakingSystem : IPreInitializationSystem, IExecutionSystem
1616
{
17-
private IEntityQuery _entities;
17+
private EntityQuery _entities;
1818
private ComponentPool<BakingEntityRef> _bakingEntities;
1919

2020
void IPreInitializationSystem.PreInitialize(IWorldGroup worlds)
2121
{
2222
var world = worlds.Default;
23+
_entities = new EntityQuery(typeof(BakingEntityRef));
24+
_entities.Initialize(world);
2325
_bakingEntities = world.Pool<BakingEntityRef>();
24-
_entities = new EntityQuery(typeof(BakingEntityRef)).Initialize(world);
2526
}
2627

2728
void IExecutionSystem.Execute()
File renamed without changes.

Runtime/Entities/InitialEntityBakingSystem.cs renamed to Runtime/Module/InitialEntityBakingSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// © 2023-2025 Nikolay Melnikov <n.melnikov@depra.org>
2+
// © 2023-2026 Depra <n.melnikov@depra.org>
33

44
using Depra.Ecs.Hybrid.Internal;
55
#if ENABLE_IL2CPP
File renamed without changes.

0 commit comments

Comments
 (0)