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.

EntityDescriptorHolderHelper.cs 1.2KB

123456789101112131415161718192021222324252627282930
  1. #if UNITY_ECS
  2. using Svelto.ECS.Hybrid;
  3. using UnityEngine;
  4. namespace Svelto.ECS.Extensions.Unity
  5. {
  6. public static class EntityDescriptorHolderHelper
  7. {
  8. public static EntityComponentInitializer 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 EntityComponentInitializer 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