Entitas  0.40.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
PublicMemberInfoEntityExtension.cs
1 namespace Entitas {
2 
3  public static class PublicMemberInfoEntityExtension {
4 
5  /// Adds copies of all specified components to the target entity.
6  /// If replaceExisting is true it will replace exisintg components.
7  public static void CopyTo(this IEntity entity, IEntity target, bool replaceExisting = false, params int[] indices) {
8  var componentIndices = indices.Length == 0
9  ? entity.GetComponentIndices()
10  : indices;
11  for(int i = 0; i < componentIndices.Length; i++) {
12  var index = componentIndices[i];
13  var component = entity.GetComponent(index);
14  var clonedComponent = target.CreateComponent(index, component.GetType());
15  component.CopyPublicMemberValues(clonedComponent);
16 
17  if(replaceExisting) {
18  target.ReplaceComponent(index, clonedComponent);
19  } else {
20  target.AddComponent(index, clonedComponent);
21  }
22  }
23  }
24  }
25 }
static void CopyTo(this IEntity entity, IEntity target, bool replaceExisting=false, params int[] indices)