forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsteroidSystem.cs
More file actions
46 lines (43 loc) · 1.44 KB
/
Copy pathAsteroidSystem.cs
File metadata and controls
46 lines (43 loc) · 1.44 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
46
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Unity.NetCode;
using Unity.Collections;
using Unity.Burst;
namespace Asteroids.Mixed
{
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
[BurstCompile]
public partial struct AsteroidSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
var builder = new EntityQueryBuilder(Allocator.Temp)
.WithAll<AsteroidTagComponentData>()
.WithNone<StaticAsteroid>();
state.RequireForUpdate(state.GetEntityQuery(builder));
}
[BurstCompile]
[WithAll(typeof(Simulate), typeof(AsteroidTagComponentData))]
[WithNone(typeof(StaticAsteroid))]
partial struct AsteroidJob : IJobEntity
{
public float deltaTime;
public void Execute(ref LocalTransform transform, in Velocity velocity)
{
transform.Position.xy += velocity.Value * deltaTime;
transform.Rotation = math.mul(transform.Rotation, quaternion.RotateZ(math.radians(100 * deltaTime)));
}
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var asteroidJob = new AsteroidJob
{
deltaTime = SystemAPI.Time.DeltaTime
};
state.Dependency = asteroidJob.ScheduleParallel(state.Dependency);
}
}
}