com.artromskiy.deltaecs.unity 0.0.53 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/Editor/BoundEntityRootEditor.cs +107 -104
- package/Editor/ComponentDropdown.cs +3 -0
- package/Editor/ComponentListController.cs +2 -1
- package/Editor/ComponentPropertyBagFields.cs +97 -93
- package/Editor/EditorLifecycle.cs +1 -0
- package/Editor/EntityInspectorTarget.cs +2 -2
- package/Editor/HierarchyMenu.cs +30 -27
- package/Editor/HierarchyNodeHandler.cs +156 -152
- package/Editor/HierarchySelection.cs +8 -5
- package/Editor/InspectorState.cs +16 -14
- package/Editor/SceneEntityInspectorView.cs +135 -133
- package/Editor/SelectionProxyBridge.cs +3 -0
- package/Editor/SelectionProxyEditor.cs +3 -2
- package/README.md +6 -6
- package/Runtime/ComponentData.cs +16 -14
- package/Runtime/EntityAuthoring.cs +1 -0
- package/Runtime/EntityContext.cs +7 -48
- package/Runtime/EntityReference.cs +1 -0
- package/Runtime/PropertyBagValueAccess.cs +6 -4
- package/Runtime/SceneAuthoring.cs +41 -40
- package/Runtime/SceneData.cs +1 -0
- package/Runtime/SceneWorld.cs +148 -153
- package/Runtime/SceneWorldExtensions.cs +2 -0
- package/Runtime/ThrowHelpers.cs +1 -0
- package/Runtime/ViewBindingSystem.cs +4 -2
- package/Runtime/ViewComponents.cs +2 -2
- package/Runtime/ViewPrefabCatalog.cs +1 -0
- package/package.json +1 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using System.Linq;
|
|
4
|
+
|
|
4
5
|
using Delta;
|
|
5
6
|
using Delta.ECS;
|
|
6
7
|
using Delta.ECS.Integration;
|
|
8
|
+
|
|
7
9
|
using UnityEditor;
|
|
8
10
|
using UnityEditor.UIElements;
|
|
11
|
+
|
|
9
12
|
using UnityEngine;
|
|
10
13
|
using UnityEngine.UIElements;
|
|
11
14
|
|
|
@@ -28,6 +31,8 @@ namespace Delta.ECS.Unity.Editor
|
|
|
28
31
|
private EntityAuthoring _authoringEntity;
|
|
29
32
|
private ComponentId[] _runtimeComponentBuffer;
|
|
30
33
|
private ComponentId[] _runtimeComponentIds;
|
|
34
|
+
|
|
35
|
+
internal int ComponentCount => _componentEntries.Count;
|
|
31
36
|
private SceneAuthoring Authoring => _target.Authoring;
|
|
32
37
|
|
|
33
38
|
public SceneEntityInspectorView(SelectionProxy proxy)
|
|
@@ -94,16 +99,141 @@ namespace Delta.ECS.Unity.Editor
|
|
|
94
99
|
return _root;
|
|
95
100
|
}
|
|
96
101
|
|
|
102
|
+
internal void ScheduleRefreshContent() => _root.schedule.Execute(RefreshContent);
|
|
103
|
+
|
|
104
|
+
private static VisualElement BuildViewField(GameObject currentView, Action<GameObject> onChanged)
|
|
105
|
+
{
|
|
106
|
+
var row = new VisualElement();
|
|
107
|
+
row.AddToClassList("ecs-view-binding");
|
|
108
|
+
|
|
109
|
+
var field = new ObjectField("Unity View")
|
|
110
|
+
{
|
|
111
|
+
objectType = typeof(GameObject),
|
|
112
|
+
allowSceneObjects = true,
|
|
113
|
+
value = currentView
|
|
114
|
+
};
|
|
115
|
+
AddInspectorFieldClasses(field);
|
|
116
|
+
row.Add(field);
|
|
117
|
+
|
|
118
|
+
var unbind = new Button(() => field.value = null)
|
|
119
|
+
{
|
|
120
|
+
text = "Unbind",
|
|
121
|
+
tooltip = "Remove the GameObject binding from this entity"
|
|
122
|
+
};
|
|
123
|
+
unbind.AddToClassList("ecs-action-button");
|
|
124
|
+
unbind.SetEnabled(currentView != null);
|
|
125
|
+
field.RegisterValueChangedCallback(evt =>
|
|
126
|
+
{
|
|
127
|
+
GameObject nextView = evt.newValue as GameObject;
|
|
128
|
+
unbind.SetEnabled(nextView != null);
|
|
129
|
+
onChanged(nextView);
|
|
130
|
+
});
|
|
131
|
+
row.Add(unbind);
|
|
132
|
+
return row;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private static void AddEntityInfo(VisualElement card, Entity entity, string stableId)
|
|
136
|
+
{
|
|
137
|
+
var idRow = new VisualElement { pickingMode = PickingMode.Ignore };
|
|
138
|
+
idRow.AddToClassList("ecs-entity-id-row");
|
|
139
|
+
idRow.Add(CreateEntityMetadata($"EntityId: {entity.Index}"));
|
|
140
|
+
idRow.Add(CreateEntityMetadata($"Generation: {entity.Generation}"));
|
|
141
|
+
card.Add(idRow);
|
|
142
|
+
card.Add(CreateEntityMetadata($"StableId: {(string.IsNullOrEmpty(stableId) ? "—" : stableId)}"));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private static Label CreateEntityMetadata(string text)
|
|
146
|
+
{
|
|
147
|
+
var label = CreateClassLabel(text, "ecs-entity-metadata");
|
|
148
|
+
label.pickingMode = PickingMode.Ignore;
|
|
149
|
+
label.style.minHeight = EditorGUIUtility.singleLineHeight;
|
|
150
|
+
return label;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private static ToolbarMenu CreateComponentMenu()
|
|
154
|
+
{
|
|
155
|
+
var menu = new ToolbarMenu { text = "⋮" };
|
|
156
|
+
menu.AddToClassList("ecs-component-menu");
|
|
157
|
+
menu.Q<VisualElement>(className: ToolbarMenu.arrowUssClassName)?.AddToClassList("ecs-component-menu-arrow");
|
|
158
|
+
menu.RegisterCallback<AttachToPanelEvent>(_ =>
|
|
159
|
+
menu.Q<VisualElement>(className: ToolbarMenu.arrowUssClassName)?.AddToClassList("ecs-component-menu-arrow"));
|
|
160
|
+
menu.RegisterCallback<PointerDownEvent>(evt => evt.StopPropagation());
|
|
161
|
+
menu.RegisterCallback<ClickEvent>(evt => evt.StopPropagation());
|
|
162
|
+
return menu;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private static Button CreateRemoveComponentButton(Action removeComponent)
|
|
166
|
+
{
|
|
167
|
+
var button = new Button(removeComponent) { text = "×", tooltip = "Remove component" };
|
|
168
|
+
button.AddToClassList("ecs-component-remove");
|
|
169
|
+
button.RegisterCallback<PointerDownEvent>(evt => evt.StopPropagation());
|
|
170
|
+
button.RegisterCallback<ClickEvent>(evt => evt.StopPropagation());
|
|
171
|
+
return button;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private static void AddHeaderAction(Toggle header, VisualElement action)
|
|
175
|
+
{
|
|
176
|
+
header.Add(action);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private static void AddInspectorFieldClasses(VisualElement field)
|
|
180
|
+
{
|
|
181
|
+
field.AddToClassList(BaseField<float>.alignedFieldUssClassName);
|
|
182
|
+
field.AddToClassList("ecs-value-field");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private static Label CreateClassLabel(string text, string className)
|
|
186
|
+
{
|
|
187
|
+
var label = new Label(text);
|
|
188
|
+
label.AddToClassList(className);
|
|
189
|
+
return label;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private static Label CreateEntityIcon() => CreateClassLabel("◆", "ecs-entity-icon");
|
|
193
|
+
|
|
194
|
+
private static ComponentDescriptor? TryGetDescriptor(ComponentData data,
|
|
195
|
+
IReadOnlyDictionary<ulong, ComponentDescriptor> descriptors)
|
|
196
|
+
{
|
|
197
|
+
ulong? schema = GetSchemaId(data);
|
|
198
|
+
return schema.HasValue && descriptors.TryGetValue(schema.Value, out ComponentDescriptor descriptor)
|
|
199
|
+
? descriptor
|
|
200
|
+
: null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private static string GetComponentMenuPath(ComponentDescriptor descriptor)
|
|
204
|
+
{
|
|
205
|
+
string namespacePath = descriptor.ValueType.Namespace?.Replace('.', '/') ?? string.Empty;
|
|
206
|
+
string shortName = GetShortTypeName(descriptor.ValueType);
|
|
207
|
+
return string.IsNullOrEmpty(namespacePath) ? shortName : $"{namespacePath}/{shortName}";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private static string GetShortTypeName(Type type)
|
|
211
|
+
{
|
|
212
|
+
string name = type.Name;
|
|
213
|
+
int genericMarker = name.IndexOf('`');
|
|
214
|
+
return genericMarker < 0 ? name : name.Substring(0, genericMarker);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private static ulong? GetSchemaId(ComponentData data)
|
|
218
|
+
{
|
|
219
|
+
return data != null && data.TryGetSchemaId(out SchemaId schema) ? schema.Value : null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private static bool IsComponentExpanded(ulong schema) =>
|
|
223
|
+
InspectorState.instance.IsComponentExpanded(schema);
|
|
224
|
+
|
|
225
|
+
private static void SetComponentExpanded(ulong schema, bool expanded) =>
|
|
226
|
+
InspectorState.instance.SetComponentExpanded(schema, expanded);
|
|
227
|
+
|
|
228
|
+
private static int GetComponentOrder(ulong schema) =>
|
|
229
|
+
InspectorState.instance.GetComponentOrder(schema);
|
|
230
|
+
|
|
97
231
|
private void OnEntitySelectionChanged()
|
|
98
232
|
{
|
|
99
233
|
SyncSelection();
|
|
100
234
|
RefreshContent();
|
|
101
235
|
}
|
|
102
236
|
|
|
103
|
-
internal int ComponentCount => _componentEntries.Count;
|
|
104
|
-
|
|
105
|
-
internal void ScheduleRefreshContent() => _root.schedule.Execute(RefreshContent);
|
|
106
|
-
|
|
107
237
|
private void OnAuthoringChanged(SceneAuthoring changedAuthoring)
|
|
108
238
|
{
|
|
109
239
|
if (changedAuthoring != Authoring || EditorApplication.isPlayingOrWillChangePlaymode)
|
|
@@ -284,55 +414,6 @@ namespace Delta.ECS.Unity.Editor
|
|
|
284
414
|
});
|
|
285
415
|
}
|
|
286
416
|
|
|
287
|
-
private static VisualElement BuildViewField(GameObject currentView, Action<GameObject> onChanged)
|
|
288
|
-
{
|
|
289
|
-
var row = new VisualElement();
|
|
290
|
-
row.AddToClassList("ecs-view-binding");
|
|
291
|
-
|
|
292
|
-
var field = new ObjectField("Unity View")
|
|
293
|
-
{
|
|
294
|
-
objectType = typeof(GameObject),
|
|
295
|
-
allowSceneObjects = true,
|
|
296
|
-
value = currentView
|
|
297
|
-
};
|
|
298
|
-
AddInspectorFieldClasses(field);
|
|
299
|
-
row.Add(field);
|
|
300
|
-
|
|
301
|
-
var unbind = new Button(() => field.value = null)
|
|
302
|
-
{
|
|
303
|
-
text = "Unbind",
|
|
304
|
-
tooltip = "Remove the GameObject binding from this entity"
|
|
305
|
-
};
|
|
306
|
-
unbind.AddToClassList("ecs-action-button");
|
|
307
|
-
unbind.SetEnabled(currentView != null);
|
|
308
|
-
field.RegisterValueChangedCallback(evt =>
|
|
309
|
-
{
|
|
310
|
-
GameObject nextView = evt.newValue as GameObject;
|
|
311
|
-
unbind.SetEnabled(nextView != null);
|
|
312
|
-
onChanged(nextView);
|
|
313
|
-
});
|
|
314
|
-
row.Add(unbind);
|
|
315
|
-
return row;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
private static void AddEntityInfo(VisualElement card, Entity entity, string stableId)
|
|
319
|
-
{
|
|
320
|
-
var idRow = new VisualElement { pickingMode = PickingMode.Ignore };
|
|
321
|
-
idRow.AddToClassList("ecs-entity-id-row");
|
|
322
|
-
idRow.Add(CreateEntityMetadata($"EntityId: {entity.Index}"));
|
|
323
|
-
idRow.Add(CreateEntityMetadata($"Generation: {entity.Generation}"));
|
|
324
|
-
card.Add(idRow);
|
|
325
|
-
card.Add(CreateEntityMetadata($"StableId: {(string.IsNullOrEmpty(stableId) ? "—" : stableId)}"));
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
private static Label CreateEntityMetadata(string text)
|
|
329
|
-
{
|
|
330
|
-
var label = CreateClassLabel(text, "ecs-entity-metadata");
|
|
331
|
-
label.pickingMode = PickingMode.Ignore;
|
|
332
|
-
label.style.minHeight = EditorGUIUtility.singleLineHeight;
|
|
333
|
-
return label;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
417
|
private VisualElement BuildAuthoringComponentCard(EntityAuthoring authoring, ComponentData data, ComponentDescriptor descriptor)
|
|
337
418
|
{
|
|
338
419
|
return BuildComponentCard(descriptor, body =>
|
|
@@ -463,32 +544,6 @@ namespace Delta.ECS.Unity.Editor
|
|
|
463
544
|
}
|
|
464
545
|
}
|
|
465
546
|
|
|
466
|
-
private static ToolbarMenu CreateComponentMenu()
|
|
467
|
-
{
|
|
468
|
-
var menu = new ToolbarMenu { text = "⋮" };
|
|
469
|
-
menu.AddToClassList("ecs-component-menu");
|
|
470
|
-
menu.Q<VisualElement>(className: ToolbarMenu.arrowUssClassName)?.AddToClassList("ecs-component-menu-arrow");
|
|
471
|
-
menu.RegisterCallback<AttachToPanelEvent>(_ =>
|
|
472
|
-
menu.Q<VisualElement>(className: ToolbarMenu.arrowUssClassName)?.AddToClassList("ecs-component-menu-arrow"));
|
|
473
|
-
menu.RegisterCallback<PointerDownEvent>(evt => evt.StopPropagation());
|
|
474
|
-
menu.RegisterCallback<ClickEvent>(evt => evt.StopPropagation());
|
|
475
|
-
return menu;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
private static Button CreateRemoveComponentButton(Action removeComponent)
|
|
479
|
-
{
|
|
480
|
-
var button = new Button(removeComponent) { text = "×", tooltip = "Remove component" };
|
|
481
|
-
button.AddToClassList("ecs-component-remove");
|
|
482
|
-
button.RegisterCallback<PointerDownEvent>(evt => evt.StopPropagation());
|
|
483
|
-
button.RegisterCallback<ClickEvent>(evt => evt.StopPropagation());
|
|
484
|
-
return button;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
private static void AddHeaderAction(Toggle header, VisualElement action)
|
|
488
|
-
{
|
|
489
|
-
header.Add(action);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
547
|
private void DrawEditableValue(VisualElement body, EntityAuthoring authoring, ComponentData data,
|
|
493
548
|
ComponentDescriptor descriptor, object value)
|
|
494
549
|
{
|
|
@@ -560,12 +615,6 @@ namespace Delta.ECS.Unity.Editor
|
|
|
560
615
|
return fieldControl;
|
|
561
616
|
}
|
|
562
617
|
|
|
563
|
-
private static void AddInspectorFieldClasses(VisualElement field)
|
|
564
|
-
{
|
|
565
|
-
field.AddToClassList(BaseField<float>.alignedFieldUssClassName);
|
|
566
|
-
field.AddToClassList("ecs-value-field");
|
|
567
|
-
}
|
|
568
|
-
|
|
569
618
|
private void BuildRuntimeEntity()
|
|
570
619
|
{
|
|
571
620
|
_runtimeBindings.Clear();
|
|
@@ -862,8 +911,7 @@ namespace Delta.ECS.Unity.Editor
|
|
|
862
911
|
return;
|
|
863
912
|
}
|
|
864
913
|
|
|
865
|
-
if (!world.Integration.TryWrite(entity, descriptor.Id, updated,
|
|
866
|
-
out _, out EcsWriteError writeError))
|
|
914
|
+
if (!world.Integration.TryWrite(entity, descriptor.Id, updated, out EcsWriteError writeError))
|
|
867
915
|
{
|
|
868
916
|
Debug.LogWarning($"Could not edit {descriptor.Name}: {writeError.Code}.");
|
|
869
917
|
RefreshRuntimeView();
|
|
@@ -891,15 +939,6 @@ namespace Delta.ECS.Unity.Editor
|
|
|
891
939
|
return value?.ToString() ?? "None";
|
|
892
940
|
}
|
|
893
941
|
|
|
894
|
-
private static Label CreateClassLabel(string text, string className)
|
|
895
|
-
{
|
|
896
|
-
var label = new Label(text);
|
|
897
|
-
label.AddToClassList(className);
|
|
898
|
-
return label;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
private static Label CreateEntityIcon() => CreateClassLabel("◆", "ecs-entity-icon");
|
|
902
|
-
|
|
903
942
|
private void RefreshRuntimeView()
|
|
904
943
|
{
|
|
905
944
|
if (SyncSelection())
|
|
@@ -1059,29 +1098,6 @@ namespace Delta.ECS.Unity.Editor
|
|
|
1059
1098
|
.ToArray();
|
|
1060
1099
|
}
|
|
1061
1100
|
|
|
1062
|
-
private static ComponentDescriptor? TryGetDescriptor(ComponentData data,
|
|
1063
|
-
IReadOnlyDictionary<ulong, ComponentDescriptor> descriptors)
|
|
1064
|
-
{
|
|
1065
|
-
ulong? schema = GetSchemaId(data);
|
|
1066
|
-
return schema.HasValue && descriptors.TryGetValue(schema.Value, out ComponentDescriptor descriptor)
|
|
1067
|
-
? descriptor
|
|
1068
|
-
: null;
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
private static string GetComponentMenuPath(ComponentDescriptor descriptor)
|
|
1072
|
-
{
|
|
1073
|
-
string namespacePath = descriptor.ValueType.Namespace?.Replace('.', '/') ?? string.Empty;
|
|
1074
|
-
string shortName = GetShortTypeName(descriptor.ValueType);
|
|
1075
|
-
return string.IsNullOrEmpty(namespacePath) ? shortName : $"{namespacePath}/{shortName}";
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
private static string GetShortTypeName(Type type)
|
|
1079
|
-
{
|
|
1080
|
-
string name = type.Name;
|
|
1081
|
-
int genericMarker = name.IndexOf('`');
|
|
1082
|
-
return genericMarker < 0 ? name : name.Substring(0, genericMarker);
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
1101
|
private void AddComponent(EntityAuthoring authoring, ComponentDescriptor descriptor)
|
|
1086
1102
|
{
|
|
1087
1103
|
Undo.RecordObject(Authoring, $"Add {GetShortTypeName(descriptor.ValueType)}");
|
|
@@ -1139,20 +1155,6 @@ namespace Delta.ECS.Unity.Editor
|
|
|
1139
1155
|
RefreshContent();
|
|
1140
1156
|
}
|
|
1141
1157
|
|
|
1142
|
-
private static ulong? GetSchemaId(ComponentData data)
|
|
1143
|
-
{
|
|
1144
|
-
return data != null && data.TryGetSchemaId(out SchemaId schema) ? schema.Value : null;
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
private static bool IsComponentExpanded(ulong schema) =>
|
|
1148
|
-
InspectorState.instance.IsComponentExpanded(schema);
|
|
1149
|
-
|
|
1150
|
-
private static void SetComponentExpanded(ulong schema, bool expanded) =>
|
|
1151
|
-
InspectorState.instance.SetComponentExpanded(schema, expanded);
|
|
1152
|
-
|
|
1153
|
-
private static int GetComponentOrder(ulong schema) =>
|
|
1154
|
-
InspectorState.instance.GetComponentOrder(schema);
|
|
1155
|
-
|
|
1156
1158
|
private void MoveComponent(ulong schema, int direction)
|
|
1157
1159
|
{
|
|
1158
1160
|
int index = _componentEntries.FindIndex(entry => entry.Descriptor?.Schema.Value == schema);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using UnityEditor;
|
|
2
|
+
|
|
2
3
|
using UnityEngine.UIElements;
|
|
3
4
|
|
|
4
5
|
namespace Delta.ECS.Unity.Editor
|
|
@@ -12,6 +13,8 @@ namespace Delta.ECS.Unity.Editor
|
|
|
12
13
|
|
|
13
14
|
public override bool RequiresConstantRepaint() => EditorApplication.isPlaying;
|
|
14
15
|
|
|
16
|
+
public override VisualElement CreateInspectorGUI() => _view.CreateGUI();
|
|
17
|
+
|
|
15
18
|
private void OnEnable()
|
|
16
19
|
{
|
|
17
20
|
_view?.Dispose();
|
|
@@ -27,7 +30,5 @@ namespace Delta.ECS.Unity.Editor
|
|
|
27
30
|
_view?.Dispose();
|
|
28
31
|
_view = null;
|
|
29
32
|
}
|
|
30
|
-
|
|
31
|
-
public override VisualElement CreateInspectorGUI() => _view.CreateGUI();
|
|
32
33
|
}
|
|
33
34
|
}
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Add the npm-compatible registry and package to the Unity project's
|
|
|
18
18
|
}
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"com.artromskiy.deltaecs.unity": "0.0.
|
|
21
|
+
"com.artromskiy.deltaecs.unity": "0.0.56"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
```
|
|
@@ -30,12 +30,12 @@ separate NuGet packages and are not included in this UPM package.
|
|
|
30
30
|
## Register components
|
|
31
31
|
|
|
32
32
|
Install `DeltaECS.Generators` in the assembly that declares components, then
|
|
33
|
-
mark component structs with `
|
|
33
|
+
mark component structs with `ComponentSchemaAttribute`:
|
|
34
34
|
|
|
35
35
|
```csharp
|
|
36
36
|
using Delta.ECS;
|
|
37
37
|
|
|
38
|
-
[
|
|
38
|
+
[ComponentSchema]
|
|
39
39
|
public struct Health
|
|
40
40
|
{
|
|
41
41
|
public float Value;
|
|
@@ -46,7 +46,7 @@ Generated module initializers expose one registration per marked component.
|
|
|
46
46
|
Register the full catalog into a layout registry, then create the world:
|
|
47
47
|
|
|
48
48
|
```csharp
|
|
49
|
-
var layouts = new
|
|
49
|
+
var layouts = new ComponentRegistry();
|
|
50
50
|
foreach (IGeneratedComponentRegistration registration in GeneratedComponentCatalog.GetRegistrations())
|
|
51
51
|
{
|
|
52
52
|
layouts.Register(registration);
|
|
@@ -58,7 +58,7 @@ using var world = new World(layouts);
|
|
|
58
58
|
To register only one generated component, pass its registration directly:
|
|
59
59
|
|
|
60
60
|
```csharp
|
|
61
|
-
var layouts = new
|
|
61
|
+
var layouts = new ComponentRegistry();
|
|
62
62
|
layouts.Register(GeneratedComponentCatalog.GetRegistration<Health>());
|
|
63
63
|
```
|
|
64
64
|
|
|
@@ -67,7 +67,7 @@ The generator reports the stable schema ID for each component. Set
|
|
|
67
67
|
unchanged after a type rename:
|
|
68
68
|
|
|
69
69
|
```csharp
|
|
70
|
-
[
|
|
70
|
+
[ComponentSchema(0x1234UL)]
|
|
71
71
|
public struct Position
|
|
72
72
|
{
|
|
73
73
|
public float X;
|
package/Runtime/ComponentData.cs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
|
+
|
|
3
4
|
using Delta.ECS;
|
|
4
5
|
using Delta.ECS.Integration;
|
|
6
|
+
|
|
5
7
|
using UnityEngine;
|
|
6
8
|
|
|
7
9
|
namespace Delta.ECS.Unity
|
|
@@ -17,12 +19,26 @@ namespace Delta.ECS.Unity
|
|
|
17
19
|
public string Json => _json;
|
|
18
20
|
public IReadOnlyList<EntityReference> EntityReferences => _entityReferences ??= new List<EntityReference>();
|
|
19
21
|
|
|
22
|
+
private List<EntityReference> EntityReferenceList =>
|
|
23
|
+
_entityReferences ??= new List<EntityReference>();
|
|
24
|
+
|
|
20
25
|
public ComponentData(ulong schemaId, string json)
|
|
21
26
|
{
|
|
22
27
|
_schemaId = schemaId.ToString("X16");
|
|
23
28
|
_json = json;
|
|
24
29
|
}
|
|
25
30
|
|
|
31
|
+
public static ComponentData CreateDefault(ComponentDescriptor descriptor)
|
|
32
|
+
{
|
|
33
|
+
if (descriptor.IsTag)
|
|
34
|
+
{
|
|
35
|
+
return new ComponentData(descriptor.Schema.Value, "{}");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
object value = Activator.CreateInstance(descriptor.ValueType);
|
|
39
|
+
return new ComponentData(descriptor.Schema.Value, JsonUtility.ToJson(value));
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
public bool TryGetSchemaId(out SchemaId schemaId)
|
|
27
43
|
{
|
|
28
44
|
if (ulong.TryParse(_schemaId, System.Globalization.NumberStyles.HexNumber, null, out ulong value))
|
|
@@ -93,19 +109,5 @@ namespace Delta.ECS.Unity
|
|
|
93
109
|
|
|
94
110
|
return string.Empty;
|
|
95
111
|
}
|
|
96
|
-
|
|
97
|
-
private List<EntityReference> EntityReferenceList =>
|
|
98
|
-
_entityReferences ??= new List<EntityReference>();
|
|
99
|
-
|
|
100
|
-
public static ComponentData CreateDefault(ComponentDescriptor descriptor)
|
|
101
|
-
{
|
|
102
|
-
if (descriptor.IsTag)
|
|
103
|
-
{
|
|
104
|
-
return new ComponentData(descriptor.Schema.Value, "{}");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
object value = Activator.CreateInstance(descriptor.ValueType);
|
|
108
|
-
return new ComponentData(descriptor.Schema.Value, JsonUtility.ToJson(value));
|
|
109
|
-
}
|
|
110
112
|
}
|
|
111
113
|
}
|
package/Runtime/EntityContext.cs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#nullable enable
|
|
2
2
|
|
|
3
3
|
using System;
|
|
4
|
+
|
|
4
5
|
using Delta.ECS;
|
|
5
6
|
|
|
6
7
|
namespace Delta.ECS.Unity
|
|
@@ -17,15 +18,18 @@ namespace Delta.ECS.Unity
|
|
|
17
18
|
/// <summary>Gets whether this context refers to a live entity.</summary>
|
|
18
19
|
public bool IsAlive => World != null && World.IsAlive(Entity);
|
|
19
20
|
|
|
21
|
+
internal EntityContext(World world, Entity entity)
|
|
22
|
+
{
|
|
23
|
+
World = world;
|
|
24
|
+
Entity = entity;
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
/// <summary>Reports whether the entity owns the specified component registration.</summary>
|
|
21
28
|
public bool Has(ComponentId componentId) => World?.Has(Entity, componentId) ?? false;
|
|
22
29
|
|
|
23
30
|
/// <summary>Reports whether the entity owns the primary registration for <typeparamref name="T"/>.</summary>
|
|
24
31
|
public bool Has<T>() => World?.Has<T>(Entity) ?? false;
|
|
25
32
|
|
|
26
|
-
/// <summary>Reports whether the entity owns the specified registration of <typeparamref name="T"/>.</summary>
|
|
27
|
-
public bool Has<T>(ComponentId componentId) => World?.Has<T>(Entity, componentId) ?? false;
|
|
28
|
-
|
|
29
33
|
/// <summary>Attempts to read the primary component for <typeparamref name="T"/>.</summary>
|
|
30
34
|
public bool TryGet<T>(out T value)
|
|
31
35
|
{
|
|
@@ -70,51 +74,6 @@ namespace Delta.ECS.Unity
|
|
|
70
74
|
/// <summary>Gets a read-only reference to the specified registration of <typeparamref name="T"/>.</summary>
|
|
71
75
|
public ref readonly T GetReadRef<T>(ComponentId componentId) => ref GetWorld().GetReadRef<T>(Entity, componentId);
|
|
72
76
|
|
|
73
|
-
/// <summary>Attempts to read the stamp for the primary component of <typeparamref name="T"/>.</summary>
|
|
74
|
-
public bool TryGetComponentStamp<T>(out Stamp stamp)
|
|
75
|
-
{
|
|
76
|
-
World? world = World;
|
|
77
|
-
if (world is null)
|
|
78
|
-
{
|
|
79
|
-
stamp = default;
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return world.TryGetComponentStamp<T>(Entity, out stamp);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/// <summary>Attempts to read the stamp for the specified component registration.</summary>
|
|
87
|
-
public bool TryGetComponentStamp(ComponentId componentId, out Stamp stamp)
|
|
88
|
-
{
|
|
89
|
-
World? world = World;
|
|
90
|
-
if (world is null)
|
|
91
|
-
{
|
|
92
|
-
stamp = default;
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return world.TryGetComponentStamp(Entity, componentId, out stamp);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/// <summary>Attempts to read the stamp for the specified registration of <typeparamref name="T"/>.</summary>
|
|
100
|
-
public bool TryGetComponentStamp<T>(ComponentId componentId, out Stamp stamp)
|
|
101
|
-
{
|
|
102
|
-
World? world = World;
|
|
103
|
-
if (world is null)
|
|
104
|
-
{
|
|
105
|
-
stamp = default;
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return world.TryGetComponentStamp<T>(Entity, componentId, out stamp);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
internal EntityContext(World world, Entity entity)
|
|
113
|
-
{
|
|
114
|
-
World = world;
|
|
115
|
-
Entity = entity;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
77
|
private World GetWorld()
|
|
119
78
|
=> World ?? UnityThrowHelpers.ThrowMissingEntityContextWorld();
|
|
120
79
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
|
+
|
|
3
4
|
using Delta.ECS;
|
|
5
|
+
|
|
4
6
|
using Unity.Properties;
|
|
5
7
|
|
|
6
8
|
namespace Delta.ECS.Unity
|
|
@@ -75,11 +77,11 @@ namespace Delta.ECS.Unity
|
|
|
75
77
|
|
|
76
78
|
private sealed class ReadPathVisitor : IPropertyBagVisitor
|
|
77
79
|
{
|
|
78
|
-
private readonly string[] _path;
|
|
79
|
-
private readonly int _pathIndex;
|
|
80
80
|
|
|
81
81
|
internal object Value;
|
|
82
82
|
internal bool Found;
|
|
83
|
+
private readonly string[] _path;
|
|
84
|
+
private readonly int _pathIndex;
|
|
83
85
|
|
|
84
86
|
internal ReadPathVisitor(string[] path, int pathIndex)
|
|
85
87
|
{
|
|
@@ -121,12 +123,12 @@ namespace Delta.ECS.Unity
|
|
|
121
123
|
|
|
122
124
|
private sealed class WritePathVisitor : IPropertyBagVisitor
|
|
123
125
|
{
|
|
126
|
+
|
|
127
|
+
internal bool Succeeded;
|
|
124
128
|
private readonly string[] _path;
|
|
125
129
|
private readonly int _pathIndex;
|
|
126
130
|
private readonly object _value;
|
|
127
131
|
|
|
128
|
-
internal bool Succeeded;
|
|
129
|
-
|
|
130
132
|
internal WritePathVisitor(string[] path, int pathIndex, object value)
|
|
131
133
|
{
|
|
132
134
|
_path = path;
|