adds Engine.RemoveComponent<TComponent>(Entity)
parent
bc66012c3d
commit
b8d66e7642
|
@ -657,6 +657,16 @@ namespace Encompass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a Component with the specified type from the given Entity.
|
||||||
|
/// Note that the Engine must Read the Component type that is being removed.
|
||||||
|
/// </summary>
|
||||||
|
protected void RemoveComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
||||||
|
{
|
||||||
|
var (componentID, _) = GetComponent<TComponent>(entity);
|
||||||
|
RemoveComponent(componentID);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the Component with the specified ID from its Entity.
|
/// Removes the Component with the specified ID from its Entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1117,5 +1117,38 @@ namespace Tests
|
||||||
|
|
||||||
readEntities.Should().BeEmpty();
|
readEntities.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Reads(typeof(MockComponent))]
|
||||||
|
class RemoveComponentByTypeEngine : Engine
|
||||||
|
{
|
||||||
|
public override void Update(double dt)
|
||||||
|
{
|
||||||
|
foreach (var (_, _, entity) in ReadComponentsIncludingEntity<MockComponent>())
|
||||||
|
{
|
||||||
|
RemoveComponent<MockComponent>(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RemoveComponentByType()
|
||||||
|
{
|
||||||
|
var worldBuilder = new WorldBuilder();
|
||||||
|
worldBuilder.AddEngine(new ReadComponentsTestEngine());
|
||||||
|
worldBuilder.AddEngine(new RemoveComponentByTypeEngine());
|
||||||
|
|
||||||
|
var entity = worldBuilder.CreateEntity();
|
||||||
|
worldBuilder.SetComponent(entity, new MockComponent { });
|
||||||
|
|
||||||
|
var entityB = worldBuilder.CreateEntity();
|
||||||
|
worldBuilder.SetComponent(entity, new MockComponent { });
|
||||||
|
|
||||||
|
var world = worldBuilder.Build();
|
||||||
|
|
||||||
|
world.Update(0.01);
|
||||||
|
world.Update(0.01);
|
||||||
|
|
||||||
|
resultComponents.Should().BeEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue