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 971B

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