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.

30 lines
1.2KB

  1. #if UNITY_5 || UNITY_5_3_OR_NEWER
  2. using Svelto.ECS.Hybrid;
  3. using UnityEngine;
  4. namespace Svelto.ECS.Extensions.Unity
  5. {
  6. public static class EntityDescriptorHolderHelper
  7. {
  8. public static EntityInitializer CreateEntity<T>(this Transform contextHolder, EGID ID,
  9. IEntityFactory factory, out T holder)
  10. where T : MonoBehaviour, IEntityDescriptorHolder
  11. {
  12. holder = contextHolder.GetComponentInChildren<T>(true);
  13. var implementors = holder.GetComponents<IImplementor>();
  14. return factory.BuildEntity(ID, holder.GetDescriptor(), implementors);
  15. }
  16. public static EntityInitializer Create<T>(this Transform contextHolder, EGID ID,
  17. IEntityFactory factory)
  18. where T : MonoBehaviour, IEntityDescriptorHolder
  19. {
  20. var holder = contextHolder.GetComponentInChildren<T>(true);
  21. var implementors = holder.GetComponents<IImplementor>();
  22. return factory.BuildEntity(ID, holder.GetDescriptor(), implementors);
  23. }
  24. }
  25. }
  26. #endif