Game.Prefabs.BuildingProperties
Assembly:
Assembly-CSharp.dll
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase
Summary:
Component used on building prefabs to override and supply building-specific property data (residential/commercial/industrial/storage settings). When present on a prefab it defines how many residential units a building can have, what resources it sells/accepts/manufactures/stores, and a space multiplier that influences apartment size/density. The component converts the inspector-facing ResourceInEditor arrays into runtime Resource flags via EconomyUtils and drives which ECS components and archetype components are added for that prefab.
Fields
-
public int m_ResidentialProperties
Tooltip: Having this component OVERRIDES the Apartment amount calculation which would otherwise come from Zone Prefab (Zone Properties component). Inserting value here will define the maximum amount of Apartments this building can have.
{{ YOUR_INFO }}: Sets the maximum number of residential units for the building. If > 0 the prefab will be treated as a residential property (adds ResidentialProperty and related components at archetype creation). -
public ResourceInEditor[] m_AllowedSold
Tooltip: Having this component OVERRIDES the value that would come from the Zone Prefab Zone Properties component. The listed resources can be sold by the property.
{{ YOUR_INFO }}: Inspector array of resources that this building can sell. Converted to runtime Resource flags with EconomyUtils.GetResources; if result != Resource.NoResource the prefab will get CommercialProperty and related components. -
public ResourceInEditor[] m_AllowedInput
Tooltip: Having this component OVERRIDES the value that would come from the Zone Prefab Zone Properties component. The listed resources can be used by the property. Can be left empty.
{{ YOUR_INFO }}: Inspector array of allowed input resources (consumed/used). Converted to runtime Resource flags; used by GetPropertyData to populate BuildingPropertyData.m_AllowedInput. -
public ResourceInEditor[] m_AllowedManufactured
Tooltip: Having this component OVERRIDES the value that would come from the Zone Prefab Zone Properties component. The listed resources can be manufactured by the property.
{{ YOUR_INFO }}: Defines manufactured output resources. If non-empty at runtime the prefab becomes an industrial/office/extractor property depending on the resource types (EconomyUtils helpers detect extractor/office resources). -
public ResourceInEditor[] m_AllowedStored
Tooltip: Having this component OVERRIDES the value that would come from the Zone Prefab Zone Properties component. The listed resources can be stored by the property.
{{ YOUR_INFO }}: If this results in any Resource flags, a WarehouseData component will be added (GetPrefabComponents) and the prefab will be treated as having storage capability (StorageProperty). -
public float m_SpaceMultiplier
Tooltip: Having this component OVERRIDES the value that would come from the Zone Prefab Zone Properties component. Space Multiplier represents the abstraction of amount of floors in a building. If the value on Space Multiplier is high the Apartments will be bigger. Does not affect how many Apartments are in a building. If value of Residential Properties is higher than Space Multiplier, then the zone type will be High Density, otherwise it will be Medium Density.
{{ YOUR_INFO }}: Affects apartment "space" (size/quality) and is used in BuildingPropertyData to influence building behavior and zoning density decisions.
Properties
- This class defines no C# properties; it exposes prefab configuration via public fields and converts them into BuildingPropertyData at initialization.
{{ YOUR_INFO }}: The related runtime data is stored in the BuildingPropertyData component that this prefab component provides to the entity.
Constructors
public BuildingProperties()
{{ YOUR_INFO }}: No explicit constructor is declared in source; the default parameterless constructor is used. Initialization work is done in overridden methods (GetPrefabComponents/GetArchetypeComponents/Initialize).
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
{{ YOUR_INFO }}: Adds ComponentType.ReadWrite() unconditionally. If m_AllowedStored (converted via EconomyUtils.GetResources) results in any resource, also adds ComponentType.ReadWrite (). This controls which runtime components are required on a prefab entity. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
{{ YOUR_INFO }}: Called when building the entity archetype for the prefab. If the prefab is not a PlaceholderBuilding, it calls AddArchetypeComponents with the BuildingPropertyData returned by GetPropertyData to add relevant runtime components (residential, commercial, industrial, storage, etc.). -
public static void AddArchetypeComponents(HashSet<ComponentType> components, BuildingPropertyData propertyData)
{{ YOUR_INFO }}: Static helper that inspects a BuildingPropertyData and adds appropriate archetype components: - Always adds Renter().
- If m_ResidentialProperties > 0: adds ResidentialProperty, BuildingNotifications, PropertyToBeOnMarket.
- If m_AllowedSold != Resource.NoResource: adds CommercialProperty, PropertyToBeOnMarket, Efficiency.
- If m_AllowedManufactured != Resource.NoResource: adds IndustrialProperty, PropertyToBeOnMarket, Efficiency; and conditionally ExtractorProperty or OfficeProperty if EconomyUtils identifies the manufactured resources as extractor/office types.
-
If m_AllowedStored != Resource.NoResource: adds IndustrialProperty, StorageProperty, PropertyToBeOnMarket. This method is key for ensuring the ECS archetype contains all systems/components needed for the property's runtime behavior.
-
public override void Initialize(EntityManager entityManager, Entity entity)
{{ YOUR_INFO }}: Called during prefab entity initialization. Sets the BuildingPropertyData component on the entity using GetPropertyData(). Ensures the entity has serialized runtime data matching the inspector configuration. -
public BuildingPropertyData GetPropertyData()
{{ YOUR_INFO }}: Converts this prefab's inspector fields into a BuildingPropertyData struct: - m_ResidentialProperties copied from field
- m_SpaceMultiplier copied from field
- m_AllowedSold = EconomyUtils.GetResources(m_AllowedSold, Resource.NoResource)
- m_AllowedInput = EconomyUtils.GetResources(m_AllowedInput, EconomyUtils.GetAllResources())
- m_AllowedManufactured = EconomyUtils.GetResources(m_AllowedManufactured, Resource.NoResource)
- m_AllowedStored = EconomyUtils.GetResources(m_AllowedStored, Resource.NoResource) This is the canonical runtime representation used by archetype/component setup and entity initialization.
Usage Example
// Example: a custom prefab component that uses BuildingProperties to set runtime data.
// In most cases the BuildingProperties component already sets BuildingPropertyData in Initialize.
// This shows how to read the property data and ensure it's applied.
[Preserve]
public class MyCustomBuildingPrefab : BuildingProperties
{
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
base.GetPrefabComponents(components);
// add other required components for this custom prefab...
}
public override void GetArchetypeComponents(HashSet<ComponentType> components)
{
base.GetArchetypeComponents(components);
// you can inspect or modify components here if needed
}
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
// Read the constructed BuildingPropertyData
var propertyData = GetPropertyData();
// Example: log or tweak runtime data before it's set (already set by base.Initialize)
Debug.Log($"Residential units: {propertyData.m_ResidentialProperties}, SpaceMultiplier: {propertyData.m_SpaceMultiplier}");
// If you needed to change something at runtime:
// propertyData.m_SpaceMultiplier *= 1.1f;
// entityManager.SetComponentData(entity, propertyData);
}
}
{{ YOUR_INFO }}: Notes and tips for modders - Use BuildingProperties on building prefabs to explicitly control what a building can produce, store, sell or consume instead of relying on Zone Properties. - The EconomyUtils.GetResources helper converts inspector-friendly ResourceInEditor arrays into the in-game Resource flags. Provide sensible defaults (Resource.NoResource) where appropriate. - Add/modify archetype components carefully: the archetype determines which systems will operate on entities and which memory layout is used. Use AddArchetypeComponents as a reference for required property-related components.