forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovementSystem.cs
More file actions
35 lines (32 loc) · 1.16 KB
/
Copy pathMovementSystem.cs
File metadata and controls
35 lines (32 loc) · 1.16 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
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
namespace HelloCube.CustomTransforms
{
public partial struct MovementSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<LocalTransform2D>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
float rotation = SystemAPI.Time.DeltaTime * 180f; // Half a rotation every second (in degrees)
float elapsedTime = (float) SystemAPI.Time.ElapsedTime;
float xPosition = math.sin(elapsedTime) * 2f - 1f;
float scale = math.sin(elapsedTime * 2f) + 1f;
scale = scale <= 0.001f ? 0f : scale;
foreach (var localTransform2D in
SystemAPI.Query<RefRW<LocalTransform2D>>()
.WithNone<Parent>())
{
localTransform2D.ValueRW.Position.x = xPosition;
localTransform2D.ValueRW.Rotation = localTransform2D.ValueRO.Rotation + rotation;
localTransform2D.ValueRW.Scale = scale;
}
}
}
}