Unit System
  • WELCOME
    • πŸ‘‹Hello
    • πŸ—ΊοΈRoadmap
    • ⛑️Support & Community
    • πŸŽ“Version - Changelog
  • Getting Started
    • πŸ”ŒImport Package
    • βš™οΈConfiguration
    • πŸ” Database
    • πŸͺŸManager Window
    • Creating a new Scene
      • Player Camera
      • Set up Player
      • Set up Player UI
      • Set up the Game World
    • Create Units
      • Resource (Crystal)
      • Research (Crystal age)
      • Resource node (Crystal Node)
      • Resource collector (Crystal)
      • Combat unit (Mage)
      • Production unit (Mage Tower)
      • Faction (Purple Cubes)
  • How it works
    • Overview
    • Modules
      • Resource
      • Production
      • Population
      • Garrison
      • Collection
  • Integration
    • Unit Selection
    • Unit Formation
    • Object Placement
Powered by GitBook
On this page
  • Key features
  • Structure
  • Usage examples
  1. How it works
  2. Modules

Production

Key features

  • Manages Player Production: Tracks and updates all components implementing IProduce on player units.

  • Realtime & Manual Production: Supports both real-time automatic production and manual updates (ideal for turn-based systems).

  • Configurable Production Tick Rate: Adjustable interval (tickInterval) for real-time production updates.

  • Delegate for Production Rules: Can automatically validate production processes based on population, resources, and requirements or allow custom validation logic.

  • Integration with Other Modules: Works alongside ResourceModule and PopulationModule to ensure produced entities do not overflow population or resource storage.


Structure

  • Production Module - Manages production, automatically or manually, realtime or turn based.

  • Active Production Capability - Defines production options, produce per request.

  • Passive Resource Production Capability - Defines passive resource production.

  • Active Production - Provides production behaviour on a game object.

  • Passive Resource Production - Provides production behaviour on a game object.

  • Production Events - Global events invoked for use like UI updates


Usage examples

Enabling Manual Production

ProductionModule productionModule = player.GetModule<ProductionModule>();
productionModule.ProduceManually = true; // Now requires manual triggering

Manually updating production for cases like turn base games.

float singleTurnDelta = 1;
productionModule.Produce(singleTurnDelta);

Using Realtime Production

By default, if ProduceManually is false, the module runs automatically based on tickInterval .

productionModule.ProduceManually = false; // Automatic real-time production

Disable Built-in validation

To disable the built-in validation delegate handling on Production Module, set the definesProductionDelegate to false .

Assigning a Custom Production Delegate

To assign custom delegate to units, first you must disable the built-in validation on the Module, they you can assign the delegate to each unit specifically:

activeProduction.Delegate = new CustomProductionDelegate();

Where CustomProductionDelegate implements IActiveProductionDelegate.

Access Production Actions

To retrieve actions defined on the unit for it's production can be done through base implementation, however you can implement your own production capability with ActiveProductionCapability interface.

// Access actions through provided implementation
if (unit.Data.TryGetCapability(out ActiveProductionCapability capability))
{
    ProductionAction[] actions = capability.ProductionActions;
    BuildUI(actions);
}

Define Custom Actions

To replace default production actions create new structure for defining your own action interface, create new production unit capability and then remove the existing capability on unit (if used) and add the new CustomProductionCapability.

public struct CustomProductionCapability : IProductionUnitCapability
{
    private CustomActions[] actions;

    void IEntityCapability.ConfigureEntity(IEntity entity)
    {
        entity.gameObject.AddComponentIfNotPresent<ActiveProduction>();
    }

    void IEntityCapability.SetDefaultValues()
    {
        // Set default values
        actions = null;
    }
}

Manage production

To start production on a unit that supports it, you should use StartProduction method.

IActiveProduction production = unit.ActiveProduction;
ResourceSO food = // provide the food asset
if (production != null)
{
    production.StartProduction(food, 5);
}

Or cancel the production and receive a list of resources that need to be freed duo to cancellation.

IActiveProduction production = unit.ActiveProuduction;

if (production) 
{
    // Cancel production
    ResourceQuantity[] freedResource = production.CancelProduction();
    // Add resources back to player
    unit.Owner.AddResource(freedResources);
}
PreviousResourceNextPopulation

Last updated 15 days ago