forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScaleSystem.cs
More file actions
35 lines (32 loc) · 1.03 KB
/
Copy pathScaleSystem.cs
File metadata and controls
35 lines (32 loc) · 1.03 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.Physics.Systems;
using Unity.Transforms;
namespace Modify
{
[RequireMatchingQueriesForUpdate]
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateBefore(typeof(PhysicsSystemGroup))]
public partial struct ScaleSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
new ScaleJob().Schedule();
}
[BurstCompile]
public partial struct ScaleJob : IJobEntity
{
public void Execute(ref Scaling scaling, ref LocalTransform localTransform)
{
localTransform.Scale = math.lerp(localTransform.Scale, scaling.Target, 0.05f);
// If we reach the target, get a new target
if (math.abs(localTransform.Scale - scaling.Target) < 0.01f)
{
scaling.Target = scaling.Target == scaling.Min ? scaling.Max : scaling.Min;
}
}
}
}
}