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

Resource

Key Features

  • Manages Player Resources: Tracks, updates, and modifies resource quantities for player-controlled entities.

  • Supports Multiple Resource Types: Works with ResourceSO to define different resources like food, wood, gold, etc.

  • Resource Calculation: Uses ResourceQuantity to compute costs and manage transactions efficiently.

  • Automatic or Manual Resource Updates: Can handle real-time updates or allow manual adjustments for turn-based systems.

  • Integration with Other Modules: Works alongside ProductionModule to ensure resource availability for unit production.


Structure

  • Resource Module – Manages resources, including adding, removing, and checking availability.

  • ResourceSO – Defines resource types as ScriptableObjects, allowing flexible creation of new resources.

  • ResourceQuantity – Represents specific amounts of resources and handles cost calculations.

  • Resource Events – Provides global events for UI updates and resource-related triggers.


Usage Examples

Adding Resources Manually

ResourceModule resourceModule = player.GetModule<ResourceModule>();
ResourceSO goldResource = ... // Reference to the gold resource scriptable object
resourceModule.AddResource(goldResource, 500); // Adds 500 gold to the player

Checking Resource Availability

ResourceQuantity requiredWood = new ResourceQuantity(woodResource, 200);
bool hasEnough = resourceModule.HasResources(new ResourceQuantity[] { requiredWood });
if (hasEnough)
{
    Debug.Log("Player has enough wood.");
}

Deducting Resources for Production

ResourceQuantity[] cost = unitBlueprint.GetProductionCost();
if (resourceModule.TryConsumeResources(cost))
{
    Debug.Log("Resources consumed, production can proceed.");
}
else
{
    Debug.Log("Not enough resources available.");
}
PreviousModulesNextProduction

Last updated 1 month ago