Game.Prefabs.ZoneProperties
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: public class
Base: ComponentBase, IZoneBuildingComponent
Summary:
ZoneProperties is a prefab component used by the game's zoning system to configure per-zone default property values that are applied to buildings created by that zone. It controls whether residential counts scale with lot size and building level, how many residential units a zone type provides, a space/floor multiplier, allowed resources for selling/input/manufacturing/storage, fire hazard multiplier, and whether rent ignores land value. During prefab-to-entity conversion this component writes a ZonePropertiesData component to the entity and provides building-specific BuildingPropertyData for buildings that don't have their own BuildingProperties.
Fields
-
public bool m_ScaleResidentials
Determines whether the number of residential units scales with the building's lot size and level. If true the number of apartments is scaled using the formula in GetBuildingPropertyData; if false the zone is treated as low density and the m_ResidentialProperties value is used as-is per building. -
public float m_ResidentialProperties
Base count (or multiplier) for residential units. If m_ScaleResidentials is true this value is multiplied by the calculated scale (based on level and lot size); otherwise it is the direct amount of apartments for the building. -
public float m_SpaceMultiplier = 1f
Represents an abstraction of apartment size / number of floors. This does not change the number of apartments but affects their "space" value. Used to determine density tier (if ResidentialProperties > SpaceMultiplier => High Density, otherwise Medium Density). -
public ResourceInEditor[] m_AllowedSold
Array of resources that this zone's properties are allowed to sell. Converted to runtime Resource[] via EconomyUtils when writing to component data. -
public ResourceInEditor[] m_AllowedInput
Array of resources that this zone's properties are allowed to consume/use. Can be empty. Converted to runtime Resource[] via EconomyUtils. -
public ResourceInEditor[] m_AllowedManufactured
Array of resources that this zone's properties can manufacture. Converted to runtime Resource[] via EconomyUtils. -
public ResourceInEditor[] m_AllowedStored
Array of resources that this zone's properties can store. Converted to runtime Resource[] via EconomyUtils. -
public float m_FireHazardMultiplier = 1f
Multiplier that affects the building's fire hazard based on this zone type. -
public bool m_IgnoreLandValue
If true, the rent price for this zone type will not be affected by land value (useful for very low-rent or fixed-rent residential types).
Properties
- None specific to this class (all configuration is done through public fields serialized in the prefab). The component writes data into the ECS components ZonePropertiesData and BuildingPropertyData during prefab conversion.
Constructors
public ZoneProperties()
Default constructor (Unity/MonoBehaviour style component). Default values: m_SpaceMultiplier = 1f, m_FireHazardMultiplier = 1f. All arrays default to null/empty until set in the inspector.
Methods
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Intended to add any component types required for the zone prefab archetype. In this implementation the method is empty (no extra archetype components added at zone-level here). -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds ZonePropertiesData to the prefab entity's component set so that the serialized zone settings are available at runtime. This ensures ZonePropertiesData is present on the entity representing the zone prefab. -
public override void Initialize(EntityManager entityManager, Entity entity)
Converts the serialized fields on this MonoBehaviour into a ZonePropertiesData struct and sets that on the ECS entity using EntityManager.SetComponentData. Uses EconomyUtils.GetResources to convert ResourceInEditor[] arrays into runtime Resource[] arrays (uses Resource.NoResource as the default for some arrays). -
public void GetBuildingPrefabComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
Adds BuildingPropertyData as a component type for building entities created by this zone (so building entities will receive building property values when spawned). -
public void InitializeBuilding(EntityManager entityManager, Entity entity, BuildingPrefab buildingPrefab, byte level)
If the building prefab does not already have BuildingProperties, this method obtains a BuildingPropertyData for the building (by calling GetBuildingPropertyData) and writes it to the building entity via SetComponentData. This is how zone-level defaults are applied to buildings lacking their own overrides. -
public void GetBuildingArchetypeComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
If the building prefab lacks BuildingProperties, this computes a BuildingPropertyData and calls BuildingProperties.AddArchetypeComponents to add any component types that BuildingProperties requires to the building archetype. -
private BuildingPropertyData GetBuildingPropertyData(BuildingPrefab buildingPrefab, byte level)
Computes and returns a BuildingPropertyData instance for a building created by this zone. Key logic: - If m_ScaleResidentials is true: scale = (1f + 0.25f * (level - 1)) * buildingPrefab.lotSize
- If false: scale = 1f
- Residential units = round(scale * m_ResidentialProperties)
- Allowed resource arrays are converted via EconomyUtils.GetResources (m_AllowedInput uses EconomyUtils.GetAllResources() as the fallback to allow inputs)
- Copies m_SpaceMultiplier into the building data.
This method encapsulates the formula used to determine apartment counts based on zone settings, lot size and building level.
Usage Example
// How the building apartment count is calculated by ZoneProperties (replicates GetBuildingPropertyData logic):
float scale = m_ScaleResidentials
? (1f + 0.25f * (level - 1)) * buildingPrefab.lotSize
: 1f;
int apartmentCount = (int)math.round(scale * m_ResidentialProperties);
// Typical initialization is handled during prefab conversion. ZoneProperties.Initialize writes
// a ZonePropertiesData component onto the prefab entity so systems can read zone defaults at runtime.
Additional notes: - ResourceInEditor[] arrays are editor-friendly representations; at runtime they are converted to the compact Resource[] via EconomyUtils. - Buildings that already have their own BuildingProperties will keep their settings; ZoneProperties only supplies BuildingPropertyData for buildings that do not declare BuildingProperties themselves.