forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitializeSystem.cs
More file actions
43 lines (38 loc) · 1.46 KB
/
Copy pathInitializeSystem.cs
File metadata and controls
43 lines (38 loc) · 1.46 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
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
namespace Graphical.RenderSwap
{
public partial struct InitializeSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<Config>();
state.RequireForUpdate<ExecuteRenderSwap>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
state.Enabled = false;
var ecbSingleton = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();
var ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged);
var config = SystemAPI.GetSingleton<Config>();
var entities = CollectionHelper.CreateNativeArray<Entity>(config.Size * config.Size,
state.WorldUnmanaged.UpdateAllocator.ToAllocator);
ecb.Instantiate(config.StateOff, entities);
var localTransform = SystemAPI.GetComponent<LocalTransform>(config.StateOff);
var offset = (1 - config.Size) / 2f;
for (int x = 0; x < config.Size; x++)
{
for (int z = 0; z < config.Size; z++)
{
localTransform.Position = new float3(x + offset, 0, z + offset);
ecb.SetComponent(entities[x + z * config.Size], localTransform);
}
}
}
}
}