Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Spawner Revamp #259

Merged
merged 9 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
341 changes: 262 additions & 79 deletions Scripts/Runtime/Entities/Lifecycle/EntitySpawnSystem.cs

Large diffs are not rendered by default.

23 changes: 10 additions & 13 deletions Scripts/Runtime/Entities/Lifecycle/IEntitySpawnDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ namespace Anvil.Unity.DOTS.Entities
/// that will populate that Entity later on during the <see cref="EntitySpawnSystem"/>s
/// update phase.
/// <example>
/// public void PopulateOnEntity(Entity entity, ref EntityCommandBuffer ecb)
/// public void PopulateOnEntity(Entity entity, in EntitySpawner entitySpawner)
/// {
/// ecb.SetComponent(entity, new ActorName(m_ActorName));
/// ecb.SetSharedComponent(entity, new EnvironmentMembershipTag(m_EnvironmentID));
/// ecb.SetComponent(entity, new ActorGridPosition(m_InitialGridPosition));
/// ecb.SetComponent(entity, new ActorGridRotation(m_InitialGridRotation));
/// entitySpawner.SetComponent(entity, new ActorName(m_ActorName));
/// entitySpawner.SetSharedComponent(entity, new EnvironmentMembershipTag(m_EnvironmentID));
/// entitySpawner.SetComponent(entity, new ActorGridPosition(m_InitialGridPosition));
/// entitySpawner.SetComponent(entity, new ActorGridRotation(m_InitialGridRotation));
/// }
/// </example>
/// Similarly, inheritance and composition can be achieved by triggering the <see cref="PopulateOnEntity"/>
/// function on child <see cref="IEntitySpawnDefinition"/>s contained within the
/// parent <see cref="IEntitySpawnDefinition"/>
/// <example>
/// public void PopulateOnEntity(Entity entity, ref EntityCommandBuffer ecb)
/// public void PopulateOnEntity(Entity entity, in EntitySpawner entitySpawner)
/// {
/// m_BaseActorDefinition.PopulateOnEntity(entity, ref ecb);
/// m_BaseActorDefinition.PopulateOnEntity(entity, entitySpawner);
/// }
/// </example>
/// </remarks>
Expand All @@ -70,16 +70,13 @@ public interface IEntitySpawnDefinition
/// <see cref="EntityArchetype"/>
/// </summary>
public ComponentType[] RequiredComponents { get; }

/// <summary>
/// Called automatically when spawning to populate a newly created <see cref="Entity"/>
/// with the data needed.
/// </summary>
/// <param name="entity">The newly created <see cref="Entity"/></param>
/// <param name="ecb">
/// The <see cref="EntityCommandBufferWithID"/> that will apply the data.
/// </param>
/// <param name="entitySpawnHelper">Helper to get Archetypes and Prototypes</param>
public void PopulateOnEntity(Entity entity, ref EntityCommandBufferWithID ecb, in EntitySpawnHelper entitySpawnHelper);
/// <param name="entitySpawner">The <see cref="EntitySpawner"/> helper struct</param>
public void PopulateOnEntity(Entity entity, in EntitySpawner entitySpawner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@ public static class IEntitySpawnDefinitionExtension
/// Create and populate an entity based on a <see cref="IEntitySpawnDefinition"/>.
/// </summary>
/// <param name="definition">The definition to create and populate an instance from.</param>
/// <param name="ecb">The <see cref="EntityCommandBufferWithID"/> to write to.</param>
/// <param name="entitySpawnHelper">The <see cref="EntitySpawnHelper"/></param>
/// <param name="entitySpawner">The <see cref="EntitySpawner"/> helper struct</param>
/// <typeparam name="TDefinition">The type of the definition that implements <see cref="IEntitySpawnDefinition"/>.</typeparam>
public static void CreateAndPopulate<TDefinition>(ref this TDefinition definition, ref EntityCommandBufferWithID ecb, in EntitySpawnHelper entitySpawnHelper)
public static void CreateAndPopulate<TDefinition>(ref this TDefinition definition, in EntitySpawner entitySpawner)
where TDefinition : unmanaged, IEntitySpawnDefinition
{
Entity entity = ecb.CreateEntity(entitySpawnHelper.GetEntityArchetypeForDefinition<TDefinition>());
definition.PopulateOnEntity(entity, ref ecb, entitySpawnHelper);
Entity entity = entitySpawner.SpawnDeferredEntity(definition);
definition.PopulateOnEntity(entity, entitySpawner);
}

/// <summary>
/// Create and populate an entity based on a <see cref="IEntitySpawnDefinition"/> using a prototype <see cref="Entity"/>
/// </summary>
/// <param name="definition">The definition to create and populate an instance from.</param>
/// <param name="ecb">The <see cref="EntityCommandBufferWithID"/> to write to.</param>
/// <param name="entitySpawnHelper">The <see cref="EntitySpawnHelper"/></param>
/// <param name="entitySpawner">The <see cref="EntitySpawner"/> helper struct</param>
/// <typeparam name="TDefinition">The type of the definition that implements <see cref="IEntitySpawnDefinition"/>.</typeparam>
public static void CreateAndPopulateWithPrototype<TDefinition>(ref this TDefinition definition, ref EntityCommandBufferWithID ecb, in EntitySpawnHelper entitySpawnHelper)
public static void CreateAndPopulateWithPrototype<TDefinition>(ref this TDefinition definition, in EntitySpawner entitySpawner)
where TDefinition : unmanaged, IEntitySpawnDefinition
{
Entity entity = ecb.Instantiate(entitySpawnHelper.GetPrototypeEntityForDefinition<TDefinition>());
definition.PopulateOnEntity(entity, ref ecb, entitySpawnHelper);
Entity entity = entitySpawner.SpawnDeferredEntityWithPrototype(definition);
definition.PopulateOnEntity(entity, entitySpawner);
}
}
}

This file was deleted.

This file was deleted.

200 changes: 0 additions & 200 deletions Scripts/Runtime/Entities/Lifecycle/JobInteraction/EntitySpawnWriter.cs

This file was deleted.

This file was deleted.

Loading