forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTornadoSpawnSystem.cs
More file actions
45 lines (39 loc) · 1.53 KB
/
Copy pathTornadoSpawnSystem.cs
File metadata and controls
45 lines (39 loc) · 1.53 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
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Scenes;
using Unity.Transforms;
namespace Tutorials.Tornado
{
[UpdateInGroup(typeof(InitializationSystemGroup))]
[UpdateAfter(typeof(SceneSystemGroup))]
public partial struct TornadoSpawnSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<Config>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var config = SystemAPI.GetSingleton<Config>();
var entities = state.EntityManager.Instantiate(config.ParticlePrefab, 1000, Allocator.Temp);
var random = Random.CreateFromIndex(1234);
foreach (var entity in entities)
{
var particle = SystemAPI.GetComponentRW<Particle>(entity);
var transform = SystemAPI.GetComponentRW<LocalTransform>(entity);
var color = SystemAPI.GetComponentRW<URPMaterialPropertyBaseColor>(entity);
transform.ValueRW.Position = new float3(random.NextFloat(-50f, 50f), random.NextFloat(0f, 50f),
random.NextFloat(-50f, 50f));
transform.ValueRW.Scale = random.NextFloat(.2f, .7f);
particle.ValueRW.radiusMult = random.NextFloat();
color.ValueRW.Value = new float4(new float3(random.NextFloat(.3f, .7f)), 1f);
}
state.Enabled = false;
}
}
}