Beispiel #1
0
        public EntityWrapper AddElementToBuffer <T>(T element) where T : struct, IBufferElementData
        {
            var buffer = EntityManagerWrapper.GetOrCreateBuffer <T>(Entity);

            buffer.Add(element);
            return(this);
        }
Beispiel #2
0
        public EntityWrapper UsingWrapper(EntityManagerWrapper wrapper, Action <EntityWrapper> callback)
        {
            var newEntityWrapper = new EntityWrapper(Entity, wrapper, Variables);

            callback.Invoke(newEntityWrapper);
            return(this);
        }
Beispiel #3
0
        public DynamicBuffer <T> GetOrCreateBuffer <T>() where T : struct, IBufferElementData
        {
            if (EntityManagerWrapper.HasComponent <T>(Entity))
            {
                return(EntityManagerWrapper.GetBuffer <T>(Entity));
            }

            return(AddBufferAndReturn <T>());
        }
Beispiel #4
0
        public EntityWrapper AddElementsToBuffer <T>(params T[] elements) where T : struct, IBufferElementData
        {
            var buffer = EntityManagerWrapper.AddBuffer <T>(Entity);

            foreach (var element in elements)
            {
                buffer.Add(element);
            }
            return(this);
        }
        public Entity Build(EntityManagerWrapper wrapper)
        {
            m_built = true;

            foreach (var step in m_steps)
            {
                step.Process(wrapper, m_variables, ref data);
            }

            return(data.entity);
        }
        public bool TryGetBuffer <T>(out DynamicBuffer <T> output) where T : struct, IBufferElementData
        {
            if (EntityManagerWrapper.HasComponent <T>(Entity))
            {
                output = EntityManagerWrapper.GetBuffer <T>(Entity);
                return(true);
            }

            output = default;
            return(false);
        }
        public bool TryGetComponent <T>(out T output) where T : struct, IComponentData
        {
            if (EntityManagerWrapper.HasComponent <T>(Entity))
            {
                output = EntityManagerWrapper.GetComponentData <T>(Entity);
                return(true);
            }

            output = default;
            return(false);
        }
        public EntityWrapper AddBuffer <T>(int repeat) where T : struct, IBufferElementData
        {
            var buffer = EntityManagerWrapper.AddBuffer <T>(Entity);

            for (var i = 0; i < repeat; i++)
            {
                buffer.Add(new T());
            }

            return(this);
        }
Beispiel #9
0
        public EntityWrapper ReplaceElementsInBuffer <T>(params T[] elements) where T : struct, IBufferElementData
        {
            if (Entity.Index < 0)
            {
                return(AddElementsToBuffer(elements));
            }

            var buffer = EntityManagerWrapper.GetOrCreateBuffer <T>(Entity);

            buffer.Clear();
            foreach (var element in elements)
            {
                buffer.Add(element);
            }
            return(this);
        }
        public virtual Entity Build(EntityManagerWrapper wrapper)
        {
            isBuilt = true;
            var entity = creationStrategy.Create(wrapper, variables);

            OnPreBuildHandler?.Invoke();

            OnPreBuild(wrapper);

            foreach (var step in steps)
            {
                step.Process(wrapper, variables, entity);
            }

            OnPostBuildHandler?.Invoke(EntityWrapper.Wrap(entity, wrapper));

            return(entity);
        }
Beispiel #11
0
        public virtual Entity Build(EntityManagerWrapper wrapper)
        {
            m_built = true;
            var entity = m_creationStrategy.Create(wrapper, m_variables);

            preBuild?.Invoke();

            OnPreBuild(wrapper);

            foreach (var step in m_steps)
            {
                step.Process(wrapper, m_variables, entity);
            }

            OnPostBuild(wrapper, entity);

            postBuild?.Invoke(EntityWrapper.Wrap(entity, wrapper));

            return(entity);
        }
Beispiel #12
0
        private EntityArchetype GetOrCreateArchetype(EntityManagerWrapper wrapper, Type archetypeType)
        {
            if (m_archetypes.ContainsKey(archetypeType))
            {
                return(m_archetypes[archetypeType]);
            }

            try
            {
                var instance = Activator.CreateInstance(archetypeType) as IArchetypeDescriptor;
                if (instance == null)
                {
                    throw new NotImplementedException($"Archetype descriptor {archetypeType} should implement {typeof(IArchetypeDescriptor)} interface and have an empty constructor");
                }

                var archetype = wrapper.CreateArchetype(instance.Components);
                m_archetypes[archetypeType] = archetype;
                return(archetype);
            }
            catch (Exception e)
            {
                throw new NotImplementedException($"Failed to instantiate archetype from archetype descriptor {archetypeType}", e);
            }
        }
Beispiel #13
0
        public static EntityWrapper Instantiate(Entity prefab, EntityCommandBuffer entityCommandBuffer)
        {
            var entityManagerWrapper = EntityManagerWrapper.FromCommandBuffer(entityCommandBuffer);

            return(new EntityWrapper(entityManagerWrapper.Instantiate(prefab), entityManagerWrapper));
        }
Beispiel #14
0
        public static EntityWrapper CreateEntity <T>(int threadId, EntityCommandBuffer.ParallelWriter entityCommandBuffer) where T : IArchetypeDescriptor
        {
            var entityManagerWrapper = EntityManagerWrapper.FromJobCommandBuffer(entityCommandBuffer, threadId);

            return(new EntityWrapper(entityManagerWrapper.CreateEntityFromArchetype <T>(), entityManagerWrapper));
        }
Beispiel #15
0
 public static EntityWrapper CreateEntity(EntityManagerWrapper entityManagerWrapper)
 {
     return(new EntityWrapper(entityManagerWrapper.CreateEntity(), entityManagerWrapper));
 }
Beispiel #16
0
        public static EntityWrapper CreateEntity <T>(EntityCommandBuffer entityCommandBuffer) where T : IArchetypeDescriptor
        {
            var entityManagerWrapper = EntityManagerWrapper.FromCommandBuffer(entityCommandBuffer);

            return(new EntityWrapper(entityManagerWrapper.CreateEntityFromArchetype <T>(), entityManagerWrapper));
        }
Beispiel #17
0
        public static EntityWrapper CreateEntity(int threadId, EntityCommandBuffer.ParallelWriter entityCommandBuffer)
        {
            var entityManagerWrapper = EntityManagerWrapper.FromJobCommandBuffer(entityCommandBuffer, threadId);

            return(new EntityWrapper(entityManagerWrapper.CreateEntity(), entityManagerWrapper));
        }
Beispiel #18
0
 public DynamicBuffer <T> AddOrCreateBuffer <T>() where T : struct, IBufferElementData
 {
     return(EntityManagerWrapper.HasComponent <T>(Entity) ? EntityManagerWrapper.GetBuffer <T>(Entity) : EntityManagerWrapper.AddBuffer <T>(Entity));
 }
Beispiel #19
0
        public static EntityWrapper CreateEntity(EntityCommandBuffer entityCommandBuffer)
        {
            var entityManagerWrapper = EntityManagerWrapper.FromCommandBuffer(entityCommandBuffer);

            return(new EntityWrapper(entityManagerWrapper.CreateEntity(), entityManagerWrapper));
        }
Beispiel #20
0
 public bool RemoveComponent <T>() where T : struct, IComponentData
 {
     return(EntityManagerWrapper.RemoveComponent <T>(Entity));
 }
Beispiel #21
0
 public void AddComponentObject(Component componentObject)
 {
     EntityManagerWrapper.AddComponentObject(Entity, componentObject);
 }
Beispiel #22
0
 public T GetComponentDataOrDefault <T>() where T : struct, IComponentData
 {
     return(EntityManagerWrapper.HasComponent <T>(Entity) ? EntityManagerWrapper.GetComponentData <T>(Entity) : default(T));
 }
Beispiel #23
0
 public bool HasComponent <T>() where T : struct
 {
     return(EntityManagerWrapper.HasComponent <T>(Entity));
 }
Beispiel #24
0
 public T GetComponentData <T>() where T : struct, IComponentData
 {
     return(EntityManagerWrapper.GetComponentData <T>(Entity));
 }
Beispiel #25
0
 public EntityWrapper AppendToBuffer <T>(T elementData) where T : struct, IBufferElementData
 {
     EntityManagerWrapper.AppendToBuffer <T>(Entity, elementData);
     return(this);
 }
Beispiel #26
0
        public static EntityWrapper Instantiate(Entity prefab, int threadId, EntityCommandBuffer.ParallelWriter entityCommandBuffer)
        {
            var entityManagerWrapper = EntityManagerWrapper.FromJobCommandBuffer(entityCommandBuffer, threadId);

            return(new EntityWrapper(entityManagerWrapper.Instantiate(prefab), entityManagerWrapper));
        }
Beispiel #27
0
 public DynamicBuffer <T> GetBuffer <T>() where T : struct, IBufferElementData
 {
     return(EntityManagerWrapper.GetBuffer <T>(Entity));
 }
Beispiel #28
0
 public EntityWrapper AddBuffer <T>() where T : struct, IBufferElementData
 {
     EntityManagerWrapper.AddBuffer <T>(Entity);
     return(this);
 }
Beispiel #29
0
 public static EntityWrapper Wrap(Entity entity, ComponentSystem componentSystem)
 {
     return(new EntityWrapper(entity, EntityManagerWrapper.From(componentSystem)));
 }
Beispiel #30
0
 public EntityWrapper Destroy()
 {
     EntityManagerWrapper.Destroy(Entity);
     Entity = Entity.Null;
     return(this);
 }