forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadingSystem.cs
More file actions
54 lines (49 loc) · 2.13 KB
/
Copy pathLoadingSystem.cs
File metadata and controls
54 lines (49 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Unity.Entities;
using Unity.Scenes;
namespace Streaming.PrefabAndSceneReferences
{
[RequireMatchingQueriesForUpdate]
[WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.Editor)]
public partial struct LoadingSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
}
public void OnUpdate(ref SystemState state)
{
var ecbSystem = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
var ecb = ecbSystem.CreateCommandBuffer(state.WorldUnmanaged);
// request load weak scene references
foreach (var (weakSceneReference, entity) in
SystemAPI.Query<RefRO<SceneReference>>()
.WithEntityAccess())
{
var sceneEntity = ecb.CreateEntity();
ecb.AddComponent(sceneEntity, new RequestSceneLoaded());
ecb.AddComponent(sceneEntity, new Unity.Entities.SceneReference(weakSceneReference.ValueRO.Value));
ecb.RemoveComponent<SceneReference>(entity);
}
// request load weak prefab references
foreach (var (weakPrefabReference, entity) in
SystemAPI.Query<RefRO<PrefabReference>>()
.WithNone<RequestEntityPrefabLoaded>()
.WithEntityAccess())
{
ecb.AddComponent(entity, new RequestEntityPrefabLoaded
{
Prefab = weakPrefabReference.ValueRO.Value
});
}
// instantiated the weak prefab references once they're loaded
foreach (var (prefabLoadResult, entity) in
SystemAPI.Query<RefRO<PrefabLoadResult>>()
.WithAll<PrefabReference>()
.WithEntityAccess())
{
ecb.Instantiate(prefabLoadResult.ValueRO.PrefabRoot);
ecb.RemoveComponent<PrefabReference>(entity);
}
}
}
}