Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenericEntityDescriptorHolder.cs 962B

123456789101112131415161718192021222324252627282930
  1. #if UNITY_5 || UNITY_5_3_OR_NEWER
  2. using System;
  3. namespace Svelto.ECS
  4. {
  5. public class GenericEntityDescriptorHolder<T, I>: UnityEngine.MonoBehaviour, IEntityDescriptorHolder where T:EntityDescriptor
  6. {
  7. public EntityDescriptor BuildDescriptorType(object[] externalImplentors)
  8. {
  9. I[] implementors;
  10. if (externalImplentors != null)
  11. {
  12. I[] baseImplentors = gameObject.GetComponents<I>();
  13. implementors = new I[externalImplentors.Length + baseImplentors.Length];
  14. Array.Copy(baseImplentors, implementors, baseImplentors.Length);
  15. Array.Copy(externalImplentors, 0, implementors, baseImplentors.Length, externalImplentors.Length);
  16. }
  17. else
  18. {
  19. implementors = gameObject.GetComponents<I>();
  20. }
  21. return (T)Activator.CreateInstance(typeof(T), implementors);
  22. }
  23. }
  24. }
  25. #endif