forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestWeakRefLoadingSystem.cs
More file actions
50 lines (42 loc) · 1.94 KB
/
Copy pathTestWeakRefLoadingSystem.cs
File metadata and controls
50 lines (42 loc) · 1.94 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
using Unity.Entities;
using Unity.Entities.Serialization;
using Unity.Scenes;
struct TestSceneReference : IComponentData
{
public EntitySceneReference SceneReference;
}
struct TestPrefabReference : IComponentData
{
public EntityPrefabReference PrefabReference;
}
[UnityEngine.ExecuteAlways]
public partial class TestWeakRefLoadingSystem : SystemBase
{
private EndSimulationEntityCommandBufferSystem m_EndSimECBSystem;
protected override void OnCreate()
{
m_EndSimECBSystem = World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>();
}
protected override void OnUpdate()
{
var ecb = m_EndSimECBSystem.CreateCommandBuffer().AsParallelWriter();
Entities.ForEach((Entity entity, int entityInQueryIndex, in TestSceneReference sceneRef) =>
{
var sceneEntity = ecb.CreateEntity(entityInQueryIndex);
ecb.AddComponent(entityInQueryIndex, sceneEntity, new RequestSceneLoaded());
ecb.AddComponent(entityInQueryIndex, sceneEntity, new SceneReference(sceneRef.SceneReference));
ecb.RemoveComponent<TestSceneReference>(entityInQueryIndex, entity);
}).ScheduleParallel();
Entities.WithNone<RequestEntityPrefabLoaded>().ForEach((Entity entity, int entityInQueryIndex, in TestPrefabReference prefabRef) =>
{
ecb.AddComponent(entityInQueryIndex, entity, new RequestEntityPrefabLoaded {Prefab = prefabRef.PrefabReference});
}).ScheduleParallel();
Entities.WithAll<TestPrefabReference>().ForEach((Entity entity, int entityInQueryIndex, in PrefabLoadResult loadedPrefab) =>
{
ecb.Instantiate(entityInQueryIndex, loadedPrefab.PrefabRoot);
ecb.RemoveComponent<TestPrefabReference>(entityInQueryIndex, entity);
ecb.RemoveComponent<RequestEntityPrefabLoaded>(entityInQueryIndex, entity);
}).ScheduleParallel();
m_EndSimECBSystem.AddJobHandleForProducer(Dependency);
}
}