forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntitySender.cs
More file actions
46 lines (42 loc) · 1.32 KB
/
Copy pathEntitySender.cs
File metadata and controls
46 lines (42 loc) · 1.32 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
43
44
45
46
using System.Collections.Generic;
using Unity.Entities;
using UnityEngine;
using UnityEngine.Serialization;
namespace Common.Scripts
{
public class EntitySender : MonoBehaviour
{
[FormerlySerializedAs("EntityReceivers")]
public GameObject[] Receivers;
class Baker : Baker<EntitySender>
{
public override void Bake(EntitySender authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
var sentEntities = AddBuffer<TargetEntity>(entity);
foreach (var receiver in authoring.Receivers)
{
List<MonoBehaviour> mbs = new List<MonoBehaviour>();
GetComponents<MonoBehaviour>(receiver, mbs);
foreach (var mb in mbs)
{
if (mb is IReceiveEntity)
{
sentEntities.Add(new TargetEntity()
{
Value = GetEntity(mb, TransformUsageFlags.Dynamic)
});
}
}
}
}
}
}
public struct TargetEntity : IBufferElementData
{
public Entity Value;
}
public interface IReceiveEntity
{
}
}