com.artromskiy.deltaecs.unity 0.0.39 → 0.0.40
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/README.md +17 -4
- package/Runtime/SceneWorld.cs +29 -3
- package/Runtime/SceneWorldExtensions.cs +59 -0
- package/Runtime/SceneWorldExtensions.cs.meta +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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.40"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
```
|
|
@@ -42,11 +42,24 @@ public struct Health
|
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Generated module initializers
|
|
46
|
-
|
|
45
|
+
Generated module initializers expose one registration per marked component.
|
|
46
|
+
Register the full catalog into a layout registry, then create the world:
|
|
47
47
|
|
|
48
48
|
```csharp
|
|
49
|
-
|
|
49
|
+
var layouts = new ComponentLayoutRegistry();
|
|
50
|
+
foreach (IGeneratedComponentRegistration registration in GeneratedComponentCatalog.GetRegistrations())
|
|
51
|
+
{
|
|
52
|
+
layouts.Register(registration);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
using var world = new World(layouts);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
To register only one generated component, pass its registration directly:
|
|
59
|
+
|
|
60
|
+
```csharp
|
|
61
|
+
var layouts = new ComponentLayoutRegistry();
|
|
62
|
+
layouts.Register(GeneratedComponentCatalog.GetRegistration<Health>());
|
|
50
63
|
```
|
|
51
64
|
|
|
52
65
|
The generator reports the stable schema ID for each component. Set
|
package/Runtime/SceneWorld.cs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
|
+
using System.Diagnostics.CodeAnalysis;
|
|
3
4
|
using Delta.ECS;
|
|
4
5
|
using Delta.ECS.Integration;
|
|
5
6
|
using UnityEngine;
|
|
@@ -69,6 +70,20 @@ namespace Delta.ECS.Unity
|
|
|
69
70
|
return false;
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
/// <summary>Resolves the live ECS world and entity currently associated with a Unity view.</summary>
|
|
74
|
+
public static bool TryGetBoundEntity(GameObject view, [NotNullWhen(true)] out World world, out Entity entity)
|
|
75
|
+
{
|
|
76
|
+
if (view != null && TryFindLiveWorld(view, out SceneWorld sceneWorld, out entity))
|
|
77
|
+
{
|
|
78
|
+
world = sceneWorld.World;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
world = null;
|
|
83
|
+
entity = default;
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
public Entity[] AuthoredEntities
|
|
73
88
|
{
|
|
74
89
|
get
|
|
@@ -104,7 +119,7 @@ namespace Delta.ECS.Unity
|
|
|
104
119
|
|
|
105
120
|
internal static SceneWorld CreatePreview(SceneData sceneData)
|
|
106
121
|
{
|
|
107
|
-
var world = new World(
|
|
122
|
+
var world = new World(CreateComponentLayouts(), DefaultEntityCapacity);
|
|
108
123
|
try
|
|
109
124
|
{
|
|
110
125
|
return new SceneWorld(world, sceneData, null,
|
|
@@ -124,7 +139,7 @@ namespace Delta.ECS.Unity
|
|
|
124
139
|
UnityThrowHelpers.ThrowArgumentNull(nameof(authoring));
|
|
125
140
|
}
|
|
126
141
|
|
|
127
|
-
var world = new World(
|
|
142
|
+
var world = new World(CreateComponentLayouts(), DefaultEntityCapacity);
|
|
128
143
|
try
|
|
129
144
|
{
|
|
130
145
|
return new SceneWorld(world, authoring.SceneData, authoring,
|
|
@@ -144,7 +159,7 @@ namespace Delta.ECS.Unity
|
|
|
144
159
|
UnityThrowHelpers.ThrowArgumentNull(nameof(authoring));
|
|
145
160
|
}
|
|
146
161
|
|
|
147
|
-
var world = new World(
|
|
162
|
+
var world = new World(CreateComponentLayouts(), RuntimeEntityCapacity);
|
|
148
163
|
try
|
|
149
164
|
{
|
|
150
165
|
return new SceneWorld(world, authoring.SceneData, authoring,
|
|
@@ -157,6 +172,17 @@ namespace Delta.ECS.Unity
|
|
|
157
172
|
}
|
|
158
173
|
}
|
|
159
174
|
|
|
175
|
+
private static ComponentLayoutRegistry CreateComponentLayouts()
|
|
176
|
+
{
|
|
177
|
+
var layouts = new ComponentLayoutRegistry();
|
|
178
|
+
foreach (IGeneratedComponentRegistration registration in GeneratedComponentCatalog.GetRegistrations())
|
|
179
|
+
{
|
|
180
|
+
layouts.Register(registration);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return layouts;
|
|
184
|
+
}
|
|
185
|
+
|
|
160
186
|
internal void RebuildAuthoringEntities()
|
|
161
187
|
{
|
|
162
188
|
ThrowIfDisposed();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#nullable enable
|
|
2
|
+
|
|
3
|
+
using System;
|
|
4
|
+
using System.Diagnostics.CodeAnalysis;
|
|
5
|
+
using Delta.ECS;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
namespace Delta.ECS.Unity
|
|
9
|
+
{
|
|
10
|
+
public static class SceneWorldExtensions
|
|
11
|
+
{
|
|
12
|
+
/// <summary>Returns the entity bound to this GameObject, or the default entity when no binding exists.</summary>
|
|
13
|
+
/// <param name="world">The bound live ECS world, or <see langword="null"/> when no binding exists.</param>
|
|
14
|
+
public static Entity GetEntity(this GameObject? view, out World? world)
|
|
15
|
+
{
|
|
16
|
+
return TryGetEntity(view, out Entity entity, out world) ? entity : default;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// <summary>Returns whether this GameObject is bound to a live ECS entity.</summary>
|
|
20
|
+
public static bool TryGetEntity(
|
|
21
|
+
this GameObject? view,
|
|
22
|
+
out Entity entity,
|
|
23
|
+
[NotNullWhen(true)] out World? world)
|
|
24
|
+
{
|
|
25
|
+
if (view != null && SceneWorld.TryGetBoundEntity(view, out World boundWorld, out entity))
|
|
26
|
+
{
|
|
27
|
+
world = boundWorld;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
entity = default;
|
|
32
|
+
world = null;
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// <summary>Returns the entity bound to this MonoBehaviour, or the default entity when no binding exists.</summary>
|
|
37
|
+
/// <param name="world">The bound live ECS world, or <see langword="null"/> when no binding exists.</param>
|
|
38
|
+
public static Entity GetEntity(this MonoBehaviour? behaviour, out World? world)
|
|
39
|
+
{
|
|
40
|
+
return TryGetEntity(behaviour, out Entity entity, out world) ? entity : default;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// <summary>Returns whether this MonoBehaviour is bound to a live ECS entity.</summary>
|
|
44
|
+
public static bool TryGetEntity(
|
|
45
|
+
this MonoBehaviour? behaviour,
|
|
46
|
+
out Entity entity,
|
|
47
|
+
[NotNullWhen(true)] out World? world)
|
|
48
|
+
{
|
|
49
|
+
if (behaviour != null)
|
|
50
|
+
{
|
|
51
|
+
return behaviour.gameObject.TryGetEntity(out entity, out world);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
entity = default;
|
|
55
|
+
world = null;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|