Core Concepts
This template is built around a few core concepts that keep the RTS logic modular and extendable.
Data objects (ScriptableObjects)
ResourceType
Represents a type of resource (e.g. wood, stone, gold).
Typical fields:
- id / displayName
- Icon for UI
- Color or other visual settings
Used by:
- ResourceManager
- ResourceProducer
- UI resource displays
BuildingType
Describes a building archetype, not a single instance.
Typical fields:
- Display name & icon
- Prefab references:
- Ghost / preview prefab
- Final building prefab
- Build cost (ResourceAmount list)
- Build time
- Flags:
- Can produce units?
- Produces resources?
- Can act as storage? (extra capacity for resources)
Used by:
- Building placement system (BuildModeController)
- Production systems (UnitProducer, ResourceProducer)
UnitType
Describes a type of unit.
Typical fields:
- Display name & icon
- Unit prefab
- Population cost
- Move / combat stats
Used by:
- UnitProducer
- Population calculations in the game manager / resource manager.
Managers
ResourceManager
Central storage for all player resources.
Responsibilities:
- Track current amounts of each ResourceType
- Track optional maximum amounts (storage capacity)
- Provide helper methods:
- GetAmount(ResourceType type)
- TrySpend(List
costs) - Add(ResourceType type, int amount)
This is what buildings / producers call when they spend or generate resources.
RTSGameManager (or similar)
High-level game state:
- Keeps references to important objects (main town center, lists of units / buildings)
- Tracks population:
- Current population
- Maximum population (sum of buildings that provide housing)
- Reacts to unit and building spawn / death events.
You can extend this to implement win/lose states, tech trees, etc.
Damage & health (Damageable)
Damageable is a base class used by both units and buildings.
Responsibilities:
- Hold maxHealth and currentHealth
- Provide TakeDamage(int amount) and Heal(int amount)
- Raise events:
- OnHealthChanged(int current, int max)
- OnDied(Damageable self)
- Optionally destroy the GameObject when health reaches zero
Typical derived classes:
- Unit : Damageable
- Building : Damageable
These derived classes add their own logic (movement, production, etc.) on top of the health system.
Selection (SelectableManager)
SelectableManager is the central authority for what is currently selected:
- Current building (if any)
- Current unit (primary unit)
- Current multi-selection list of units
It raises events such as:
- OnBuildingSelected(Building building)
- OnUnitSelected(Unit unit)
- OnUnitsSelectionChanged(IReadOnlyList
units)
UI and gameplay systems subscribe to these events to update panels, show unit info, highlight objects, etc.
Selection itself (mouse raycasts, drag selection rectangle) is handled by UnitSelectionController, which then calls into SelectableManager.