forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartesianGridMovementAuthoring.cs
More file actions
39 lines (35 loc) · 1.08 KB
/
Copy pathCartesianGridMovementAuthoring.cs
File metadata and controls
39 lines (35 loc) · 1.08 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
using Unity.Entities;
using Unity.Rendering;
using UnityEngine;
[RequiresEntityConversion]
[AddComponentMenu("DOTS Samples/GridPath/Cartesian Grid Movement")]
[ConverterVersion("macton", 4)]
public class CartesianGridMovementAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
public enum MovementOptions
{
Bounce,
FollowTarget
};
[Range(0.0f, 2.0f)]
public float Speed;
public MovementOptions Movement;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponentData(entity, new CartesianGridDirection
{
Value = 0, // default N
});
dstManager.AddComponentData(entity, new CartesianGridSpeed
{
Value = (ushort)(Speed * 1024.0f)
});
dstManager.AddComponentData(entity, new CartesianGridCoordinates
{
x = 0,
y = 0
});
if (Movement == MovementOptions.FollowTarget)
dstManager.AddComponentData(entity, new CartesianGridFollowTarget());
}
}