com.artromskiy.deltaecs.unity 0.0.53 → 0.0.54
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 +4 -0
- package/Editor/SceneEntityInspectorView.cs +1 -2
- package/README.md +6 -6
- package/Runtime/EntityContext.cs +0 -42
- package/Runtime/SceneWorld.cs +13 -20
- package/Runtime/ViewBindingSystem.cs +2 -2
- package/Runtime/ViewComponents.cs +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -862,8 +862,7 @@ namespace Delta.ECS.Unity.Editor
|
|
|
862
862
|
return;
|
|
863
863
|
}
|
|
864
864
|
|
|
865
|
-
if (!world.Integration.TryWrite(entity, descriptor.Id, updated,
|
|
866
|
-
out _, out EcsWriteError writeError))
|
|
865
|
+
if (!world.Integration.TryWrite(entity, descriptor.Id, updated, out EcsWriteError writeError))
|
|
867
866
|
{
|
|
868
867
|
Debug.LogWarning($"Could not edit {descriptor.Name}: {writeError.Code}.");
|
|
869
868
|
RefreshRuntimeView();
|
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.54"
|
|
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/EntityContext.cs
CHANGED
|
@@ -23,9 +23,6 @@ namespace Delta.ECS.Unity
|
|
|
23
23
|
/// <summary>Reports whether the entity owns the primary registration for <typeparamref name="T"/>.</summary>
|
|
24
24
|
public bool Has<T>() => World?.Has<T>(Entity) ?? false;
|
|
25
25
|
|
|
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
26
|
/// <summary>Attempts to read the primary component for <typeparamref name="T"/>.</summary>
|
|
30
27
|
public bool TryGet<T>(out T value)
|
|
31
28
|
{
|
|
@@ -70,45 +67,6 @@ namespace Delta.ECS.Unity
|
|
|
70
67
|
/// <summary>Gets a read-only reference to the specified registration of <typeparamref name="T"/>.</summary>
|
|
71
68
|
public ref readonly T GetReadRef<T>(ComponentId componentId) => ref GetWorld().GetReadRef<T>(Entity, componentId);
|
|
72
69
|
|
|
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
70
|
internal EntityContext(World world, Entity entity)
|
|
113
71
|
{
|
|
114
72
|
World = world;
|
package/Runtime/SceneWorld.cs
CHANGED
|
@@ -120,7 +120,7 @@ namespace Delta.ECS.Unity
|
|
|
120
120
|
|
|
121
121
|
internal static SceneWorld CreatePreview(SceneData sceneData)
|
|
122
122
|
{
|
|
123
|
-
var world =
|
|
123
|
+
var world = CreateWorld(DefaultEntityCapacity);
|
|
124
124
|
try
|
|
125
125
|
{
|
|
126
126
|
return new SceneWorld(world, sceneData, null,
|
|
@@ -140,7 +140,7 @@ namespace Delta.ECS.Unity
|
|
|
140
140
|
UnityThrowHelpers.ThrowArgumentNull(nameof(authoring));
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
var world =
|
|
143
|
+
var world = CreateWorld(DefaultEntityCapacity);
|
|
144
144
|
try
|
|
145
145
|
{
|
|
146
146
|
return new SceneWorld(world, authoring.SceneData, authoring,
|
|
@@ -160,7 +160,7 @@ namespace Delta.ECS.Unity
|
|
|
160
160
|
UnityThrowHelpers.ThrowArgumentNull(nameof(authoring));
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
var world =
|
|
163
|
+
var world = CreateWorld(RuntimeEntityCapacity);
|
|
164
164
|
try
|
|
165
165
|
{
|
|
166
166
|
return new SceneWorld(world, authoring.SceneData, authoring,
|
|
@@ -173,15 +173,15 @@ namespace Delta.ECS.Unity
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
private static
|
|
176
|
+
private static World CreateWorld(int initialEntityCapacity)
|
|
177
177
|
{
|
|
178
|
-
var layouts = new
|
|
178
|
+
var layouts = new ComponentRegistry();
|
|
179
179
|
foreach (IGeneratedComponentRegistration registration in GeneratedComponentCatalog.GetRegistrations())
|
|
180
180
|
{
|
|
181
181
|
layouts.Register(registration);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
return layouts;
|
|
184
|
+
return new World(layouts, initialEntityCapacity);
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
internal void RebuildAuthoringEntities()
|
|
@@ -245,8 +245,8 @@ namespace Delta.ECS.Unity
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
object value = data.CreateValue(descriptor.ValueType, ResolveEntity);
|
|
248
|
-
if (_integration.TryRead(entity, descriptor.Id, out
|
|
249
|
-
&& !_integration.TryWrite(entity, descriptor.Id, value,
|
|
248
|
+
if (_integration.TryRead(entity, descriptor.Id, out _, out _)
|
|
249
|
+
&& !_integration.TryWrite(entity, descriptor.Id, value, out EcsWriteError error))
|
|
250
250
|
{
|
|
251
251
|
Debug.LogError($"Failed to load {descriptor.Name} on '{authoring.Name}': {error.Code}.");
|
|
252
252
|
}
|
|
@@ -428,7 +428,7 @@ namespace Delta.ECS.Unity
|
|
|
428
428
|
return false;
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
-
if (!_integration.TryWrite(entity, descriptor.Id, value,
|
|
431
|
+
if (!_integration.TryWrite(entity, descriptor.Id, value, out error))
|
|
432
432
|
{
|
|
433
433
|
return false;
|
|
434
434
|
}
|
|
@@ -495,7 +495,7 @@ namespace Delta.ECS.Unity
|
|
|
495
495
|
return false;
|
|
496
496
|
}
|
|
497
497
|
|
|
498
|
-
if (!_integration.TryWrite(entity, descriptor.Id, value,
|
|
498
|
+
if (!_integration.TryWrite(entity, descriptor.Id, value, out error))
|
|
499
499
|
{
|
|
500
500
|
_integration.Remove(entity, new[] { descriptor.Id });
|
|
501
501
|
failureReason = $"The default component value could not be written ({error.Code}).";
|
|
@@ -516,7 +516,7 @@ namespace Delta.ECS.Unity
|
|
|
516
516
|
|
|
517
517
|
public bool TryFindFirstEntity<T>(out Entity entity) where T : struct
|
|
518
518
|
{
|
|
519
|
-
if (_world.
|
|
519
|
+
if (_world.Components.TryGetPrimary(typeof(T), out ComponentId componentId))
|
|
520
520
|
{
|
|
521
521
|
foreach (Entity candidate in _entitiesByStableId.Values)
|
|
522
522
|
{
|
|
@@ -534,7 +534,7 @@ namespace Delta.ECS.Unity
|
|
|
534
534
|
|
|
535
535
|
public bool HasComponent<T>(Entity entity) where T : struct =>
|
|
536
536
|
_world.IsAlive(entity)
|
|
537
|
-
&& _world.
|
|
537
|
+
&& _world.Components.TryGetPrimary(typeof(T), out ComponentId componentId)
|
|
538
538
|
&& _world.Has(entity, componentId);
|
|
539
539
|
|
|
540
540
|
internal bool TryGetAuthoring(string stableId, out EntityAuthoring authoring)
|
|
@@ -568,14 +568,7 @@ namespace Delta.ECS.Unity
|
|
|
568
568
|
_stableIdsByEntity.Clear();
|
|
569
569
|
_viewsByEntity.Clear();
|
|
570
570
|
_entitiesByView.Clear();
|
|
571
|
-
|
|
572
|
-
{
|
|
573
|
-
_integration.Shutdown();
|
|
574
|
-
}
|
|
575
|
-
catch (InvalidOperationException)
|
|
576
|
-
{
|
|
577
|
-
// The ECS integration may already have been shut down during domain teardown.
|
|
578
|
-
}
|
|
571
|
+
_integration.Shutdown();
|
|
579
572
|
|
|
580
573
|
if (_ownsWorld)
|
|
581
574
|
{
|
|
@@ -25,8 +25,8 @@ namespace Delta.ECS.Unity
|
|
|
25
25
|
_catalog = catalog ?? UnityThrowHelpers.ThrowArgumentNull<ViewPrefabCatalog>(nameof(catalog));
|
|
26
26
|
_world = _sceneWorld.World;
|
|
27
27
|
|
|
28
|
-
ComponentId viewTokenId = _world.
|
|
29
|
-
_viewBoundId = _world.
|
|
28
|
+
ComponentId viewTokenId = _world.Components.GetPrimary<ViewToken>();
|
|
29
|
+
_viewBoundId = _world.Components.GetPrimary<ViewBound>();
|
|
30
30
|
Query query = _world.WhereAll(stackalloc ComponentId[1] { viewTokenId })
|
|
31
31
|
.WhereNone(stackalloc ComponentId[1] { _viewBoundId });
|
|
32
32
|
_bindOperation = _world.ForEachEntity(in query, QueueViewBinding);
|
|
@@ -10,7 +10,7 @@ namespace Delta.ECS.Unity
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/// <summary>Selects the Unity prefab used to represent an entity.</summary>
|
|
13
|
-
[
|
|
13
|
+
[ComponentSchema(0x405B11F5A17E14A1UL)]
|
|
14
14
|
public readonly struct ViewToken
|
|
15
15
|
{
|
|
16
16
|
/// <summary>Gets the identifier of the view prefab in a <see cref="ViewPrefabCatalog"/>.</summary>
|
|
@@ -21,7 +21,7 @@ namespace Delta.ECS.Unity
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/// <summary>Marks an entity whose Unity view has already been bound.</summary>
|
|
24
|
-
[
|
|
24
|
+
[ComponentSchema(0xB31CB42A81D3B164UL)]
|
|
25
25
|
public struct ViewBound
|
|
26
26
|
{
|
|
27
27
|
}
|