forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileLODBakingSystem.cs
More file actions
39 lines (35 loc) · 1.74 KB
/
Copy pathTileLODBakingSystem.cs
File metadata and controls
39 lines (35 loc) · 1.74 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
using Unity.Collections;
using Unity.Entities;
using Unity.Entities.Serialization;
namespace Streaming.SceneManagement.CompleteSample
{
// This system will store the LOD distances meta data for the sections
[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
partial struct TileLODBakingSystem : ISystem
{
// Cannot be Burst-compiled because it calls SerializeUtility.GetSceneSectionEntity
public void OnUpdate(ref SystemState state)
{
// Remove all the previously stored data, for incremental baking
var cleaningQuery = SystemAPI.QueryBuilder().WithAll<TileLODRange, SectionMetadataSetup>().Build();
state.EntityManager.RemoveComponent<TileLODBaking>(cleaningQuery);
var radiusQuery = SystemAPI.QueryBuilder().WithAll<TileLODBaking>().Build();
var sectionLODs = radiusQuery.ToComponentDataArray<TileLODBaking>(Allocator.Temp);
EntityQuery sectionEntityQuery = default;
for (int index = 0; index < sectionLODs.Length; ++index)
{
// Get the section entity during baking
var sectionEntity = SerializeUtility.GetSceneSectionEntity(sectionLODs[index].Section,
state.EntityManager, ref sectionEntityQuery, true);
// Add the meta information to the sections
var lowerRadius = sectionLODs[index].LowerRadius;
var higherRadius = sectionLODs[index].HigherRadius;
state.EntityManager.AddComponentData(sectionEntity, new TileLODRange
{
LowerRadiusSq = lowerRadius * lowerRadius,
HigherRadiusSq = higherRadius * higherRadius
});
}
}
}
}