Skip to content

Resources & Economy

The economy system is centered around ResourceType, ResourceAmount, and ResourceManager.


Resource types

ResourceType is a ScriptableObject describing:

  • An internal ID and display name
  • Icon
  • Optional color or category

Examples:

  • Wood
  • Stone
  • Gold
  • Food

These are referenced by:

  • Building costs
  • Unit costs
  • Passive or active production
  • Storage capacity

Resource amounts

A small helper struct or class like ResourceAmount is used to couple:

  • ResourceType type
  • int amount

This allows lists like:

  • Building cost: [ (Wood, 50), (Stone, 25) ]
  • Storage capacity: [ (Wood, 500), (Stone, 300) ]

ResourceManager

ResourceManager holds:

  • _amounts: current amount per ResourceType
  • _maxAmounts: maximum capacity per ResourceType (if you use storage buildings)

Typical methods:

  • int GetAmount(ResourceType type)
  • int GetMaxAmount(ResourceType type)
  • void Add(ResourceType type, int value)
  • bool TrySpend(IEnumerable costs)

Spending and adding resources is done by buildings, units, and producers through these methods.


Storage buildings

Some buildings can extend maximum resource capacity.

Typical pattern:

  • In BuildingType you have a list: extraStorage: List
  • When a storage building is completed:
  • For each ResourceAmount in extraStorage:
    • Increase _maxAmounts[type] by amount
  • When a storage building is destroyed:
  • Optionally reduce capacity again
  • Optionally clamp current amounts to the new max

Production (ResourceProducer)

ResourceProducer handles generating resources over time.

Key ideas:

  • Works only when the building is completed (not under construction)
  • May require assigned workers
  • Has a production interval (e.g. every X seconds)
  • Produces a list of ResourceAmount per tick

On each tick:

  • Check if the building is active and has enough workers.
  • If yes, add resources to ResourceManager.