forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOscillatingSystem.cs
More file actions
24 lines (23 loc) · 896 Bytes
/
Copy pathOscillatingSystem.cs
File metadata and controls
24 lines (23 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
namespace Streaming.SceneManagement.Common
{
// OscillatingSystem will move each oscillating entity in sample
public partial struct OscillatingSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var time = (float)SystemAPI.Time.ElapsedTime;
foreach (var (transform, oscillating) in
SystemAPI.Query<RefRW<LocalTransform>, RefRO<Oscillating>>())
{
var amplitude = oscillating.ValueRO.Direction * oscillating.ValueRO.Amplitude;
var wave = math.sin(2f * math.PI * oscillating.ValueRO.Frequency * time + oscillating.ValueRO.Offset);
transform.ValueRW.Position = oscillating.ValueRO.Center + amplitude * wave;
}
}
}
}