forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpinnerSystem.cs
More file actions
42 lines (37 loc) · 1.36 KB
/
Copy pathSpinnerSystem.cs
File metadata and controls
42 lines (37 loc) · 1.36 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
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Transforms;
namespace Graphical.RenderSwap
{
public partial struct SpinnerSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<Config>();
state.RequireForUpdate<ExecuteRenderSwap>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var angle = math.radians((float)SystemAPI.Time.ElapsedTime * 120);
var axis = float3.zero;
math.sincos(angle, out axis.x, out axis.z);
var meshInfoLookup = SystemAPI.GetComponentLookup<MaterialMeshInfo>();
var config = SystemAPI.GetSingleton<Config>();
var meshOn = meshInfoLookup[config.StateOn];
var meshOff = meshInfoLookup[config.StateOff];
foreach (var (meshInfo, transform) in
SystemAPI.Query<RefRW<MaterialMeshInfo>, RefRO<LocalTransform>>()
.WithAll<SpinTile>())
{
var pos = transform.ValueRO.Position;
var closest = math.dot(pos, axis) * axis;
var sqDist = math.distancesq(closest, pos);
meshInfo.ValueRW = sqDist < 10f ? meshOn : meshOff;
}
}
}
}