Game.Prefabs.Attraction
Assembly:
Assembly-CSharp.dll
Namespace:
Game.Prefabs
Type:
public class Attraction : ComponentBase, IServiceUpgrade
Base:
ComponentBase, IServiceUpgrade
Summary:
Represents an attraction prefab component used by building prefabs. Stores a base attractiveness value and controls which ECS components are added to the prefab's archetype and instances. Adds an AttractionData component for all instances and conditionally adds an AttractivenessProvider component when the attraction should provide attractiveness to the simulation (depends on m_Attractiveness and whether the prefab is a ServiceUpgrade).
Fields
public int m_Attractiveness
Integer value that determines how much attractiveness this prefab provides. Used to populate AttractionData and to decide whether to add an AttractivenessProvider component to archetypes/upgrades.
Properties
- This class does not declare any public properties.
Constructors
public Attraction()
Default parameterless constructor. The class relies on overridden lifecycle methods (GetPrefabComponents, GetArchetypeComponents, Initialize) to configure ECS components; no special construction logic is provided.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the components that every instance of the prefab should have. This implementation always adds AttractionData as a ReadWrite component type. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds components that should be present on the archetype for this prefab. If the prefab is not a ServiceUpgrade (GetComponent() == null) and m_Attractiveness > 0, this method adds AttractivenessProvider as a ReadWrite component so spawned entities can provide attractiveness. -
public void GetUpgradeComponents(HashSet<ComponentType> components)
Implements IServiceUpgrade. When m_Attractiveness > 0, this adds AttractivenessProvider as a ReadWrite component to the upgrade archetype (no ServiceUpgrade check here). -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when an instance is created. Sets the AttractionData component on the given entity using the value from m_Attractiveness.
Usage Example
// Example of extending or customizing behavior while keeping base functionality.
public class CustomAttraction : Attraction
{
public override void Initialize(EntityManager entityManager, Entity entity)
{
// Ensure base initialization (writes AttractionData.m_Attractiveness)
base.Initialize(entityManager, entity);
// Additional initialization logic (optional):
// e.g. add other components, set tags, or adjust data based on game state.
}
}