Building
Key Features
Manages Player Builders: Provides a number of available builders, and interface for finding and/or starting building process.
Collection Module Integration: With configuration you can specify if builders should attempt to collect resources after working or when no more work is available for building and their last building task was a resource depot. If builders are also collectors, they can be sent to nearby resource node with a new task.
Building Animation: Abstract implementation for building animation behaviour and simple raise building implementation.
Auto-Build: Allows buildings to build automatically, without using builders.
Event-Driven Updates: Triggers events for UI or gameplay reactions when entity starts, updates or completes building process.
Structure
Building Module - Easy access to available builders and finding nearby buildable entities.
Builder Capability - Defines builders capabilities like build interval, build power, enable auto-pickup and pickup.
Builder - Management of the builder's state and interactions.
Buildable Capability - Defines if entity builds automatically and if it updates health during building process.
EntityBuilding - Implements
IBuildable
and manages the state of entity's building process.Build Events - Global events for tracking building processes: start, update, cancel, building complete, builder finished work.
Usage Examples
Control Builders
When you wish to send builders to build a nearby buildable entity.
[SerializeField] APlayer player;
// Example method for sending builder to build a nearby entity (if any found).
public void SendBuilderToWork(IBuilder builder)
{
if (!player.TryGetModule(out BuildingModule module))
{
Debug.Log("Player has no building module.");
return;
}
// Filter full is relevant only when you limit concurrent
// interactions on a given entity.
if (module.FindClosestBuildableEntity(builder, filterFull: true, out var buildable))
{
Debug.Log("No buildable entity found.");
return;
}
builder.GoBuildEntity(buildable);
}
Retrieves module from the player if present
Module finds the closest buildable entity available
Optionally filters out full buildable entities. You can limit max active interactions on a building so only 1 or 2 builders can be assigned to it, or disable limitation completely.
Builder is ordered to go build, which internally starts the
BuildTargetTask
if the target is valid.
When you wish to send a builder to the specific target.
IEntity targetEntity = // Get entity reference.
IBuilder builder = // Get builder reference.
// Check if entity can be built.
if (targetEntity.Buildable == null) return;
// Optionally you can check if entity is already built at this time.
if (targetEntity.Buildable.IsBuilt) return;
// Send builder to work
builder.GoBuildEntity(targetEntity.Buildable);
Display Available Builders
To show available builders to player on UI, you can use module's interface.
// Get all idle builders, with no active tasks.
var availableBuilders = module.GetAvailableBuilders();
// Get all builders, idle or not.
var allBuilders = module.Builders;
Finish Building Immediately
If there is a need to complete building process instantly.
IBuildable buildable = entity.Buildable;
buildable.FinishBuilding();
Last updated