forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadPrefabSystem.cs
More file actions
33 lines (29 loc) · 1.11 KB
/
Copy pathLoadPrefabSystem.cs
File metadata and controls
33 lines (29 loc) · 1.11 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
using Unity.Burst;
using Unity.Entities;
using Unity.Scenes;
namespace Baking.PrefabReference
{
public partial struct LoadPrefabSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<Config>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
state.Enabled = false;
var config = SystemAPI.GetSingleton<Config>();
var configEntity = SystemAPI.GetSingletonEntity<Config>();
// Adding the RequestEntityPrefabLoaded component will request the prefab to be loaded.
// It will load the entity scene file corresponding to the prefab and add a PrefabLoadResult
// component to the entity. The PrefabLoadResult component contains the entity you can use to
// instantiate the prefab (see the PrefabReferenceSpawnerSystem system).
state.EntityManager.AddComponentData(configEntity, new RequestEntityPrefabLoaded
{
Prefab = config.PrefabReference
});
}
}
}