Game.Prefabs.ExtractorParameterPrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
ExtractorParameterPrefab is a Unity prefab class used to configure consumption and productivity thresholds for natural-resource extractors (agriculture, aquaculture, forestry, mining, oil) in the game. The class exposes inspector-editable fields (with tooltips and default values) and, on initialization, writes those values into an ECS component (ExtractorParameterData) so systems and jobs can read extractor parameters at runtime.
Fields
-
public float m_FertilityConsumption = 0.1f
Amount of fertility resource consumed per produced agricultural unit. Default: 0.1. -
public float m_FishConsumption = 0.1f
Amount of fish resource consumed per produced aquacultural unit. Default: 0.1. -
public float m_OreConsumption = 500000f
Amount of ore that can be extracted before efficiency decays significantly (value used to determine efficiency drop). Default: 500000. -
public float m_ForestConsumption = 1f
Amount of forest resource consumed per produced wood unit. Default: 1. -
public float m_OilConsumption = 100000f
Amount of oil that can be extracted before efficiency decays significantly. Default: 100000. -
public float m_FullFertility = 0.5f
If resource concentration falls below this limit, agricultural productivity starts to drop. Default: 0.5. -
public float m_FullFish = 0.5f
If resource concentration falls below this limit, aquacultural productivity starts to drop. Default: 0.5. -
public float m_FullOre = 0.8f
If resource concentration falls below this limit, mining productivity starts to drop. Default: 0.8. -
public float m_FullOil = 0.8f
If resource concentration falls below this limit, oil extraction productivity starts to drop. Default: 0.8.
Notes: - These are public inspector fields decorated with Tooltip attributes. They are intended to be tuned in the prefab asset in the editor and then transferred to ECS data in LateInitialize.
Properties
- None declared on this class. (All configuration is exposed via public fields and written into the ExtractorParameterData component.)
Constructors
public ExtractorParameterPrefab()
No explicit constructor is declared in the source; the default parameterless constructor is used.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required component types to the provided set of prefab components. Implementation:- Calls base.GetPrefabComponents(components).
-
Adds ComponentType.ReadWrite
() so the prefab entity will include ExtractorParameterData at runtime. This is the ECS component that stores the extractor parameters copied from the prefab fields. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Calls base.GetArchetypeComponents(components). This override currently does not add any additional archetype components beyond the base class behavior. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called during prefab initialization to write the prefab field values into the ECS component on the entity. Implementation details: - Calls base.LateInitialize(entityManager, entity).
- Ensures the PrefabSystem exists via entityManager.World.GetOrCreateSystemManaged
(). - Calls entityManager.SetComponentData(entity, new ExtractorParameterData { ... }) filling all fields (m_FertilityConsumption, m_FishConsumption, m_ForestConsumption, m_OreConsumption, m_OilConsumption, m_FullFertility, m_FullFish, m_FullOil, m_FullOre) from the prefab's public fields.
- Effectively copies the inspector values into the runtime ECS component so systems can read extractor parameters without referencing the MonoBehaviour prefab.
Usage Example
- Typical workflow: configure an ExtractorParameterPrefab in the editor (set the public float fields). On prefab initialization the values are transferred to the ExtractorParameterData component on the prefab entity. Systems can then read the component.
Example code snippets:
1) How the prefab writes data (already implemented in LateInitialize — shown here for clarity):
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
entityManager.World.GetOrCreateSystemManaged<PrefabSystem>();
entityManager.SetComponentData(entity, new ExtractorParameterData
{
m_FertilityConsumption = m_FertilityConsumption,
m_FishConsumption = m_FishConsumption,
m_ForestConsumption = m_ForestConsumption,
m_OreConsumption = m_OreConsumption,
m_OilConsumption = m_OilConsumption,
m_FullFertility = m_FullFertility,
m_FullFish = m_FullFish,
m_FullOil = m_FullOil,
m_FullOre = m_FullOre
});
}
2) How a system can read the data at runtime:
// inside a System or other ECS-aware code with an EntityManager reference
if (entityManager.HasComponent<ExtractorParameterData>(prefabEntity))
{
var paramsData = entityManager.GetComponentData<ExtractorParameterData>(prefabEntity);
float fertilityConsumption = paramsData.m_FertilityConsumption;
float oreConsumption = paramsData.m_OreConsumption;
// use these values in processing extractor productivity/consumption calculations
}
Notes and tips: - Tune values on the prefab asset using the inspector; avoid changing them at runtime unless you intend to alter extractor behavior globally. - Because values are stored in an ECS component, they are efficient to read inside jobs and ECS systems.