* Converted all SnapGridPositionChangedEvent subscriptions to AnchorStateChangedEvent. * Fixes power tests with new anchored requirements. * Moved AnchorableComponent into construction. AnchorableComponent now uses Transform.Anchored. * Fixed bug with nodes, power works again. * Adds lifetime stages to Component. * Update Engine to v0.4.70.
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
#nullable enable
|
|
using System.Collections.Generic;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
|
|
namespace Content.Client.Spawners
|
|
{
|
|
/// <summary>
|
|
/// Spawns a set of entities on the client only, and removes them when this component is removed.
|
|
/// </summary>
|
|
[RegisterComponent]
|
|
public class ClientEntitySpawnerComponent : Component
|
|
{
|
|
public override string Name => "ClientEntitySpawner";
|
|
|
|
[DataField("prototypes")] private List<string> _prototypes = new() { "HVDummyWire" };
|
|
|
|
private readonly List<IEntity> _entity = new();
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SpawnEntities();
|
|
}
|
|
|
|
protected override void OnRemove()
|
|
{
|
|
RemoveEntities();
|
|
base.OnRemove();
|
|
}
|
|
|
|
private void SpawnEntities()
|
|
{
|
|
foreach (var proto in _prototypes)
|
|
{
|
|
var entity = Owner.EntityManager.SpawnEntity(proto, Owner.Transform.Coordinates);
|
|
_entity.Add(entity);
|
|
}
|
|
}
|
|
|
|
private void RemoveEntities()
|
|
{
|
|
foreach (var entity in _entity)
|
|
{
|
|
Owner.EntityManager.DeleteEntity(entity);
|
|
}
|
|
}
|
|
}
|
|
}
|