forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateConnectionPositionSystem.cs
More file actions
84 lines (78 loc) · 2.42 KB
/
Copy pathUpdateConnectionPositionSystem.cs
File metadata and controls
84 lines (78 loc) · 2.42 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.NetCode;
using Unity.Transforms;
namespace Asteroids.Server
{
[BurstCompile]
[RequireMatchingQueriesForUpdate]
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial struct UpdateConnectionPositionSystem : ISystem
{
#if !ENABLE_TRANSFORM_V1
ComponentLookup<LocalTransform> m_Transforms;
#else
ComponentLookup<Translation> m_Translations;
#endif
[BurstCompile]
public void OnCreate(ref SystemState state)
{
#if !ENABLE_TRANSFORM_V1
m_Transforms = state.GetComponentLookup<LocalTransform>(true);
#else
m_Translations = state.GetComponentLookup<Translation>(true);
#endif
}
[BurstCompile]
public void OnDestroy(ref SystemState state)
{
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
#if !ENABLE_TRANSFORM_V1
m_Transforms.Update(ref state);
var updateJob = new UpdateConnectionPositionSystemJob
{
transformFromEntity = m_Transforms
};
#else
m_Translations.Update(ref state);
var updateJob = new UpdateConnectionPositionSystemJob
{
translationFromEntity = m_Translations
};
#endif
updateJob.Schedule();
}
[BurstCompile]
partial struct UpdateConnectionPositionSystemJob : IJobEntity
{
#if !ENABLE_TRANSFORM_V1
[ReadOnly] public ComponentLookup<LocalTransform> transformFromEntity;
#else
[ReadOnly] public ComponentLookup<Translation> translationFromEntity;
#endif
public void Execute(ref GhostConnectionPosition conPos, in CommandTargetComponent target)
{
#if !ENABLE_TRANSFORM_V1
if (!transformFromEntity.HasComponent(target.targetEntity))
return;
conPos = new GhostConnectionPosition
{
Position = transformFromEntity[target.targetEntity].Position
};
#else
if (!translationFromEntity.HasComponent(target.targetEntity))
return;
conPos = new GhostConnectionPosition
{
Position = translationFromEntity[target.targetEntity].Value
};
#endif
}
}
}
}