forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneLoaderSystem.cs
More file actions
32 lines (30 loc) · 1.18 KB
/
Copy pathSceneLoaderSystem.cs
File metadata and controls
32 lines (30 loc) · 1.18 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
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Scenes;
namespace Streaming.SceneManagement.SceneLoading
{
public partial struct SceneLoaderSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<SceneReference>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
// Loads all the requested scenes and removes the requests from the entities
var query = SystemAPI.QueryBuilder().WithAll<SceneReference>().Build();
var requests = query.ToComponentDataArray<SceneReference>(Allocator.Temp);
for (int i = 0; i < requests.Length; i += 1)
{
// Creates an entity with scene-related components, which will later trigger scene loading
// in the scene loading systems.
// (Because this method may add a component to an entity, it cannot be called in a foreach query.)
SceneSystem.LoadSceneAsync(state.WorldUnmanaged, requests[i].Value);
}
state.EntityManager.DestroyEntity(query);
}
}
}