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,5 +1,6 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
|
+
|
|
3
4
|
using UnityEngine;
|
|
4
5
|
using UnityEngine.SceneManagement;
|
|
5
6
|
|
|
@@ -25,6 +26,46 @@ namespace Delta.ECS.Unity
|
|
|
25
26
|
|
|
26
27
|
internal SceneData SceneData => _sceneData ??= new SceneData();
|
|
27
28
|
|
|
29
|
+
internal static SceneAuthoring FindForScene(Scene scene)
|
|
30
|
+
{
|
|
31
|
+
if (!scene.IsValid())
|
|
32
|
+
{
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
SceneAuthoring[] authorings = Resources.FindObjectsOfTypeAll<SceneAuthoring>();
|
|
37
|
+
for (int i = 0; i < authorings.Length; i++)
|
|
38
|
+
{
|
|
39
|
+
SceneAuthoring authoring = authorings[i];
|
|
40
|
+
if (authoring != null && authoring.gameObject.scene == scene)
|
|
41
|
+
{
|
|
42
|
+
return authoring;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
internal static SceneAuthoring GetOrCreateForScene(Scene scene)
|
|
50
|
+
{
|
|
51
|
+
if (!scene.IsValid() || !scene.isLoaded)
|
|
52
|
+
{
|
|
53
|
+
UnityThrowHelpers.ThrowArgument("Scene authoring requires a valid, loaded scene.", nameof(scene));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
SceneAuthoring existing = FindForScene(scene);
|
|
57
|
+
if (existing != null)
|
|
58
|
+
{
|
|
59
|
+
return existing;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var authoringObject = new GameObject(AuthoringObjectName);
|
|
63
|
+
SceneManager.MoveGameObjectToScene(authoringObject, scene);
|
|
64
|
+
SceneAuthoring authoring = authoringObject.AddComponent<SceneAuthoring>();
|
|
65
|
+
authoringObject.hideFlags |= HideFlags.HideInHierarchy;
|
|
66
|
+
return authoring;
|
|
67
|
+
}
|
|
68
|
+
|
|
28
69
|
internal bool TryGetView(string stableId, out GameObject view)
|
|
29
70
|
{
|
|
30
71
|
EnsureBindingIndex();
|
|
@@ -84,46 +125,6 @@ namespace Delta.ECS.Unity
|
|
|
84
125
|
|
|
85
126
|
internal bool RemoveView(string stableId) => SetView(stableId, null);
|
|
86
127
|
|
|
87
|
-
internal static SceneAuthoring FindForScene(Scene scene)
|
|
88
|
-
{
|
|
89
|
-
if (!scene.IsValid())
|
|
90
|
-
{
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
SceneAuthoring[] authorings = Resources.FindObjectsOfTypeAll<SceneAuthoring>();
|
|
95
|
-
for (int i = 0; i < authorings.Length; i++)
|
|
96
|
-
{
|
|
97
|
-
SceneAuthoring authoring = authorings[i];
|
|
98
|
-
if (authoring != null && authoring.gameObject.scene == scene)
|
|
99
|
-
{
|
|
100
|
-
return authoring;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
internal static SceneAuthoring GetOrCreateForScene(Scene scene)
|
|
108
|
-
{
|
|
109
|
-
if (!scene.IsValid() || !scene.isLoaded)
|
|
110
|
-
{
|
|
111
|
-
UnityThrowHelpers.ThrowArgument("Scene authoring requires a valid, loaded scene.", nameof(scene));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
SceneAuthoring existing = FindForScene(scene);
|
|
115
|
-
if (existing != null)
|
|
116
|
-
{
|
|
117
|
-
return existing;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
var authoringObject = new GameObject(AuthoringObjectName);
|
|
121
|
-
SceneManager.MoveGameObjectToScene(authoringObject, scene);
|
|
122
|
-
SceneAuthoring authoring = authoringObject.AddComponent<SceneAuthoring>();
|
|
123
|
-
authoringObject.hideFlags |= HideFlags.HideInHierarchy;
|
|
124
|
-
return authoring;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
128
|
private void OnValidate()
|
|
128
129
|
{
|
|
129
130
|
SceneData.EnsureStableIds();
|
package/Runtime/SceneData.cs
CHANGED
package/Runtime/SceneWorld.cs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using System.Diagnostics.CodeAnalysis;
|
|
4
|
+
|
|
4
5
|
using Delta.ECS;
|
|
5
6
|
using Delta.ECS.Integration;
|
|
7
|
+
|
|
6
8
|
using UnityEngine;
|
|
7
9
|
using UnityEngine.SceneManagement;
|
|
8
10
|
|
|
@@ -30,97 +32,174 @@ namespace Delta.ECS.Unity
|
|
|
30
32
|
private bool _disposed;
|
|
31
33
|
|
|
32
34
|
public World World => _world;
|
|
35
|
+
|
|
36
|
+
public Entity[] AuthoredEntities
|
|
37
|
+
{
|
|
38
|
+
get
|
|
39
|
+
{
|
|
40
|
+
var entities = new Entity[_entitiesByStableId.Count];
|
|
41
|
+
_entitiesByStableId.Values.CopyTo(entities, 0);
|
|
42
|
+
return entities;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
33
45
|
internal IEcsWorld Integration => _integration;
|
|
34
46
|
internal SceneData SceneData => _sceneData;
|
|
35
47
|
internal Scene UnityScene => _authoring != null ? _authoring.gameObject.scene : default;
|
|
36
48
|
internal bool IsBound => !_disposed;
|
|
37
49
|
|
|
50
|
+
internal SceneWorld(World world, SceneData sceneData)
|
|
51
|
+
: this(world, sceneData, null, ownsWorld: false, registerLiveWorld: true)
|
|
52
|
+
{
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private SceneWorld(World world, SceneData sceneData,
|
|
56
|
+
SceneAuthoring authoring, bool ownsWorld, bool registerLiveWorld)
|
|
57
|
+
{
|
|
58
|
+
_world = world ?? UnityThrowHelpers.ThrowArgumentNull<World>(nameof(world));
|
|
59
|
+
_sceneData = sceneData ?? UnityThrowHelpers.ThrowArgumentNull<SceneData>(nameof(sceneData));
|
|
60
|
+
_authoring = authoring;
|
|
61
|
+
_integration = world;
|
|
62
|
+
_ownsWorld = ownsWorld;
|
|
63
|
+
|
|
64
|
+
_sceneData.EnsureStableIds();
|
|
65
|
+
_integration.Initialize();
|
|
66
|
+
RebuildAuthoringEntities();
|
|
67
|
+
if (registerLiveWorld)
|
|
68
|
+
{
|
|
69
|
+
LiveWorlds.Add(this);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
38
73
|
/// <summary>Returns the integration-owned runtime context for a loaded Unity scene.</summary>
|
|
39
74
|
public static SceneWorld GetForScene(Scene scene) => SceneWorldRuntime.GetForScene(scene);
|
|
40
75
|
|
|
41
|
-
|
|
76
|
+
/// <summary>Resolves the live ECS world and entity currently associated with a Unity view.</summary>
|
|
77
|
+
public static bool TryGetBoundEntity(GameObject view, [NotNullWhen(true)] out World world, out Entity entity)
|
|
42
78
|
{
|
|
43
|
-
|
|
79
|
+
if (view != null && TryFindLiveWorld(view, out SceneWorld sceneWorld, out entity))
|
|
44
80
|
{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
sceneWorld = candidate;
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
81
|
+
world = sceneWorld.World;
|
|
82
|
+
return true;
|
|
51
83
|
}
|
|
52
84
|
|
|
53
|
-
|
|
85
|
+
world = null;
|
|
86
|
+
entity = default;
|
|
54
87
|
return false;
|
|
55
88
|
}
|
|
56
89
|
|
|
57
|
-
|
|
90
|
+
/// <summary>Registers a transient runtime association; it is not written into scene data.</summary>
|
|
91
|
+
public bool BindView(Entity entity, GameObject view)
|
|
58
92
|
{
|
|
59
|
-
|
|
93
|
+
if (view == null || !_integration.IsAlive(entity))
|
|
60
94
|
{
|
|
61
|
-
|
|
62
|
-
if (!candidate._disposed && candidate.TryGetEntity(view, out entity))
|
|
63
|
-
{
|
|
64
|
-
sceneWorld = candidate;
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
95
|
+
return false;
|
|
67
96
|
}
|
|
68
97
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
98
|
+
UnityEngine.EntityId viewId = view.GetEntityId();
|
|
99
|
+
if (_entitiesByView.TryGetValue(viewId, out Entity previousEntity))
|
|
100
|
+
{
|
|
101
|
+
_viewsByEntity.Remove(previousEntity);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (_viewsByEntity.TryGetValue(entity, out GameObject previousView) && previousView != null)
|
|
105
|
+
{
|
|
106
|
+
_entitiesByView.Remove(previousView.GetEntityId());
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_viewsByEntity[entity] = view;
|
|
110
|
+
_entitiesByView[viewId] = entity;
|
|
111
|
+
return true;
|
|
72
112
|
}
|
|
73
113
|
|
|
74
|
-
|
|
75
|
-
public static bool TryGetBoundEntity(GameObject view, [NotNullWhen(true)] out World world, out Entity entity)
|
|
114
|
+
public void UnbindView(Entity entity)
|
|
76
115
|
{
|
|
77
|
-
if (
|
|
116
|
+
if (_viewsByEntity.Remove(entity, out GameObject view) && view != null)
|
|
78
117
|
{
|
|
79
|
-
|
|
80
|
-
|
|
118
|
+
_entitiesByView.Remove(view.GetEntityId());
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public bool TryFindFirstEntity<T>(out Entity entity) where T : struct
|
|
123
|
+
{
|
|
124
|
+
if (_world.Components.TryGetPrimary(typeof(T), out ComponentId componentId))
|
|
125
|
+
{
|
|
126
|
+
foreach (Entity candidate in _entitiesByStableId.Values)
|
|
127
|
+
{
|
|
128
|
+
if (_integration.IsAlive(candidate) && _world.Has(candidate, componentId))
|
|
129
|
+
{
|
|
130
|
+
entity = candidate;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
81
134
|
}
|
|
82
135
|
|
|
83
|
-
world = null;
|
|
84
136
|
entity = default;
|
|
85
137
|
return false;
|
|
86
138
|
}
|
|
87
139
|
|
|
88
|
-
public Entity
|
|
140
|
+
public bool HasComponent<T>(Entity entity) where T : struct =>
|
|
141
|
+
_world.IsAlive(entity)
|
|
142
|
+
&& _world.Components.TryGetPrimary(typeof(T), out ComponentId componentId)
|
|
143
|
+
&& _world.Has(entity, componentId);
|
|
144
|
+
|
|
145
|
+
public void Dispose()
|
|
89
146
|
{
|
|
90
|
-
|
|
147
|
+
if (_disposed)
|
|
91
148
|
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
_disposed = true;
|
|
153
|
+
LiveWorlds.Remove(this);
|
|
154
|
+
DestroyCurrentAuthoringEntities();
|
|
155
|
+
_entitiesByStableId.Clear();
|
|
156
|
+
_stableIdsByEntity.Clear();
|
|
157
|
+
_viewsByEntity.Clear();
|
|
158
|
+
_entitiesByView.Clear();
|
|
159
|
+
_integration.Shutdown();
|
|
160
|
+
|
|
161
|
+
if (_ownsWorld)
|
|
162
|
+
{
|
|
163
|
+
_world.Dispose();
|
|
95
164
|
}
|
|
96
165
|
}
|
|
97
166
|
|
|
98
|
-
internal
|
|
99
|
-
: this(world, sceneData, null, ownsWorld: false, registerLiveWorld: true)
|
|
167
|
+
internal static bool TryFindLiveWorld(SceneData sceneData, out SceneWorld sceneWorld)
|
|
100
168
|
{
|
|
169
|
+
for (int i = LiveWorlds.Count - 1; i >= 0; i--)
|
|
170
|
+
{
|
|
171
|
+
SceneWorld candidate = LiveWorlds[i];
|
|
172
|
+
if (!candidate._disposed && ReferenceEquals(candidate._sceneData, sceneData))
|
|
173
|
+
{
|
|
174
|
+
sceneWorld = candidate;
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
sceneWorld = null;
|
|
180
|
+
return false;
|
|
101
181
|
}
|
|
102
182
|
|
|
103
|
-
|
|
104
|
-
SceneAuthoring authoring, bool ownsWorld, bool registerLiveWorld)
|
|
183
|
+
internal static bool TryFindLiveWorld(GameObject view, out SceneWorld sceneWorld, out Entity entity)
|
|
105
184
|
{
|
|
106
|
-
|
|
107
|
-
_sceneData = sceneData ?? UnityThrowHelpers.ThrowArgumentNull<SceneData>(nameof(sceneData));
|
|
108
|
-
_authoring = authoring;
|
|
109
|
-
_integration = world;
|
|
110
|
-
_ownsWorld = ownsWorld;
|
|
111
|
-
|
|
112
|
-
_sceneData.EnsureStableIds();
|
|
113
|
-
_integration.Initialize();
|
|
114
|
-
RebuildAuthoringEntities();
|
|
115
|
-
if (registerLiveWorld)
|
|
185
|
+
for (int i = LiveWorlds.Count - 1; i >= 0; i--)
|
|
116
186
|
{
|
|
117
|
-
LiveWorlds
|
|
187
|
+
SceneWorld candidate = LiveWorlds[i];
|
|
188
|
+
if (!candidate._disposed && candidate.TryGetEntity(view, out entity))
|
|
189
|
+
{
|
|
190
|
+
sceneWorld = candidate;
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
118
193
|
}
|
|
194
|
+
|
|
195
|
+
sceneWorld = null;
|
|
196
|
+
entity = default;
|
|
197
|
+
return false;
|
|
119
198
|
}
|
|
120
199
|
|
|
121
200
|
internal static SceneWorld CreatePreview(SceneData sceneData)
|
|
122
201
|
{
|
|
123
|
-
var world =
|
|
202
|
+
var world = CreateWorld(DefaultEntityCapacity);
|
|
124
203
|
try
|
|
125
204
|
{
|
|
126
205
|
return new SceneWorld(world, sceneData, null,
|
|
@@ -140,7 +219,7 @@ namespace Delta.ECS.Unity
|
|
|
140
219
|
UnityThrowHelpers.ThrowArgumentNull(nameof(authoring));
|
|
141
220
|
}
|
|
142
221
|
|
|
143
|
-
var world =
|
|
222
|
+
var world = CreateWorld(DefaultEntityCapacity);
|
|
144
223
|
try
|
|
145
224
|
{
|
|
146
225
|
return new SceneWorld(world, authoring.SceneData, authoring,
|
|
@@ -160,7 +239,7 @@ namespace Delta.ECS.Unity
|
|
|
160
239
|
UnityThrowHelpers.ThrowArgumentNull(nameof(authoring));
|
|
161
240
|
}
|
|
162
241
|
|
|
163
|
-
var world =
|
|
242
|
+
var world = CreateWorld(RuntimeEntityCapacity);
|
|
164
243
|
try
|
|
165
244
|
{
|
|
166
245
|
return new SceneWorld(world, authoring.SceneData, authoring,
|
|
@@ -173,17 +252,6 @@ namespace Delta.ECS.Unity
|
|
|
173
252
|
}
|
|
174
253
|
}
|
|
175
254
|
|
|
176
|
-
private static ComponentLayoutRegistry CreateComponentLayouts()
|
|
177
|
-
{
|
|
178
|
-
var layouts = new ComponentLayoutRegistry();
|
|
179
|
-
foreach (IGeneratedComponentRegistration registration in GeneratedComponentCatalog.GetRegistrations())
|
|
180
|
-
{
|
|
181
|
-
layouts.Register(registration);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return layouts;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
255
|
internal void RebuildAuthoringEntities()
|
|
188
256
|
{
|
|
189
257
|
ThrowIfDisposed();
|
|
@@ -245,8 +313,8 @@ namespace Delta.ECS.Unity
|
|
|
245
313
|
}
|
|
246
314
|
|
|
247
315
|
object value = data.CreateValue(descriptor.ValueType, ResolveEntity);
|
|
248
|
-
if (_integration.TryRead(entity, descriptor.Id, out
|
|
249
|
-
&& !_integration.TryWrite(entity, descriptor.Id, value,
|
|
316
|
+
if (_integration.TryRead(entity, descriptor.Id, out _, out _)
|
|
317
|
+
&& !_integration.TryWrite(entity, descriptor.Id, value, out EcsWriteError error))
|
|
250
318
|
{
|
|
251
319
|
Debug.LogError($"Failed to load {descriptor.Name} on '{authoring.Name}': {error.Code}.");
|
|
252
320
|
}
|
|
@@ -315,38 +383,6 @@ namespace Delta.ECS.Unity
|
|
|
315
383
|
return false;
|
|
316
384
|
}
|
|
317
385
|
|
|
318
|
-
/// <summary>Registers a transient runtime association; it is not written into scene data.</summary>
|
|
319
|
-
public bool BindView(Entity entity, GameObject view)
|
|
320
|
-
{
|
|
321
|
-
if (view == null || !_integration.IsAlive(entity))
|
|
322
|
-
{
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
UnityEngine.EntityId viewId = view.GetEntityId();
|
|
327
|
-
if (_entitiesByView.TryGetValue(viewId, out Entity previousEntity))
|
|
328
|
-
{
|
|
329
|
-
_viewsByEntity.Remove(previousEntity);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (_viewsByEntity.TryGetValue(entity, out GameObject previousView) && previousView != null)
|
|
333
|
-
{
|
|
334
|
-
_entitiesByView.Remove(previousView.GetEntityId());
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
_viewsByEntity[entity] = view;
|
|
338
|
-
_entitiesByView[viewId] = entity;
|
|
339
|
-
return true;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
public void UnbindView(Entity entity)
|
|
343
|
-
{
|
|
344
|
-
if (_viewsByEntity.Remove(entity, out GameObject view) && view != null)
|
|
345
|
-
{
|
|
346
|
-
_entitiesByView.Remove(view.GetEntityId());
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
386
|
internal bool TryGetDescriptor(ComponentData data, out ComponentDescriptor descriptor)
|
|
351
387
|
{
|
|
352
388
|
descriptor = default;
|
|
@@ -428,7 +464,7 @@ namespace Delta.ECS.Unity
|
|
|
428
464
|
return false;
|
|
429
465
|
}
|
|
430
466
|
|
|
431
|
-
if (!_integration.TryWrite(entity, descriptor.Id, value,
|
|
467
|
+
if (!_integration.TryWrite(entity, descriptor.Id, value, out error))
|
|
432
468
|
{
|
|
433
469
|
return false;
|
|
434
470
|
}
|
|
@@ -495,7 +531,7 @@ namespace Delta.ECS.Unity
|
|
|
495
531
|
return false;
|
|
496
532
|
}
|
|
497
533
|
|
|
498
|
-
if (!_integration.TryWrite(entity, descriptor.Id, value,
|
|
534
|
+
if (!_integration.TryWrite(entity, descriptor.Id, value, out error))
|
|
499
535
|
{
|
|
500
536
|
_integration.Remove(entity, new[] { descriptor.Id });
|
|
501
537
|
failureReason = $"The default component value could not be written ({error.Code}).";
|
|
@@ -514,29 +550,6 @@ namespace Delta.ECS.Unity
|
|
|
514
550
|
&& _integration.Remove(entity, new[] { descriptor.Id });
|
|
515
551
|
}
|
|
516
552
|
|
|
517
|
-
public bool TryFindFirstEntity<T>(out Entity entity) where T : struct
|
|
518
|
-
{
|
|
519
|
-
if (_world.Layouts.TryGetPrimary(typeof(T), out ComponentId componentId))
|
|
520
|
-
{
|
|
521
|
-
foreach (Entity candidate in _entitiesByStableId.Values)
|
|
522
|
-
{
|
|
523
|
-
if (_integration.IsAlive(candidate) && _world.Has(candidate, componentId))
|
|
524
|
-
{
|
|
525
|
-
entity = candidate;
|
|
526
|
-
return true;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
entity = default;
|
|
532
|
-
return false;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
public bool HasComponent<T>(Entity entity) where T : struct =>
|
|
536
|
-
_world.IsAlive(entity)
|
|
537
|
-
&& _world.Layouts.TryGetPrimary(typeof(T), out ComponentId componentId)
|
|
538
|
-
&& _world.Has(entity, componentId);
|
|
539
|
-
|
|
540
553
|
internal bool TryGetAuthoring(string stableId, out EntityAuthoring authoring)
|
|
541
554
|
{
|
|
542
555
|
IList<EntityAuthoring> entities = _sceneData.Entities;
|
|
@@ -554,33 +567,15 @@ namespace Delta.ECS.Unity
|
|
|
554
567
|
return false;
|
|
555
568
|
}
|
|
556
569
|
|
|
557
|
-
|
|
570
|
+
private static World CreateWorld(int initialEntityCapacity)
|
|
558
571
|
{
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
_disposed = true;
|
|
565
|
-
LiveWorlds.Remove(this);
|
|
566
|
-
DestroyCurrentAuthoringEntities();
|
|
567
|
-
_entitiesByStableId.Clear();
|
|
568
|
-
_stableIdsByEntity.Clear();
|
|
569
|
-
_viewsByEntity.Clear();
|
|
570
|
-
_entitiesByView.Clear();
|
|
571
|
-
try
|
|
572
|
-
{
|
|
573
|
-
_integration.Shutdown();
|
|
574
|
-
}
|
|
575
|
-
catch (InvalidOperationException)
|
|
572
|
+
var layouts = new ComponentRegistry();
|
|
573
|
+
foreach (IGeneratedComponentRegistration registration in GeneratedComponentCatalog.GetRegistrations())
|
|
576
574
|
{
|
|
577
|
-
|
|
575
|
+
layouts.Register(registration);
|
|
578
576
|
}
|
|
579
577
|
|
|
580
|
-
|
|
581
|
-
{
|
|
582
|
-
_world.Dispose();
|
|
583
|
-
}
|
|
578
|
+
return new World(layouts, initialEntityCapacity);
|
|
584
579
|
}
|
|
585
580
|
|
|
586
581
|
private void DestroyCurrentAuthoringEntities()
|
|
@@ -612,6 +607,17 @@ namespace Delta.ECS.Unity
|
|
|
612
607
|
private static readonly Dictionary<Scene, SceneWorld> WorldsByScene = new();
|
|
613
608
|
private static bool _initialized;
|
|
614
609
|
|
|
610
|
+
internal static SceneWorld GetForScene(Scene scene)
|
|
611
|
+
{
|
|
612
|
+
if (!Application.isPlaying)
|
|
613
|
+
{
|
|
614
|
+
UnityThrowHelpers.ThrowInvalidOperation("Runtime scene worlds are only available in Play Mode.");
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
EnsureInitialized();
|
|
618
|
+
return EnsureForScene(scene);
|
|
619
|
+
}
|
|
620
|
+
|
|
615
621
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
|
616
622
|
private static void ResetForPlaySession()
|
|
617
623
|
{
|
|
@@ -628,17 +634,6 @@ namespace Delta.ECS.Unity
|
|
|
628
634
|
}
|
|
629
635
|
}
|
|
630
636
|
|
|
631
|
-
internal static SceneWorld GetForScene(Scene scene)
|
|
632
|
-
{
|
|
633
|
-
if (!Application.isPlaying)
|
|
634
|
-
{
|
|
635
|
-
UnityThrowHelpers.ThrowInvalidOperation("Runtime scene worlds are only available in Play Mode.");
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
EnsureInitialized();
|
|
639
|
-
return EnsureForScene(scene);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
637
|
private static void EnsureInitialized()
|
|
643
638
|
{
|
|
644
639
|
if (_initialized)
|
package/Runtime/ThrowHelpers.cs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#nullable enable
|
|
2
2
|
|
|
3
3
|
using System.Collections.Generic;
|
|
4
|
+
|
|
4
5
|
using Delta.ECS;
|
|
6
|
+
|
|
5
7
|
using UnityEngine;
|
|
6
8
|
using UnityEngine.SceneManagement;
|
|
7
9
|
|
|
@@ -25,8 +27,8 @@ namespace Delta.ECS.Unity
|
|
|
25
27
|
_catalog = catalog ?? UnityThrowHelpers.ThrowArgumentNull<ViewPrefabCatalog>(nameof(catalog));
|
|
26
28
|
_world = _sceneWorld.World;
|
|
27
29
|
|
|
28
|
-
ComponentId viewTokenId = _world.
|
|
29
|
-
_viewBoundId = _world.
|
|
30
|
+
ComponentId viewTokenId = _world.Components.GetPrimary<ViewToken>();
|
|
31
|
+
_viewBoundId = _world.Components.GetPrimary<ViewBound>();
|
|
30
32
|
Query query = _world.WhereAll(stackalloc ComponentId[1] { viewTokenId })
|
|
31
33
|
.WhereNone(stackalloc ComponentId[1] { _viewBoundId });
|
|
32
34
|
_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
|
}
|