Game.Prefabs.ObjectAchievementComponent
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
ObjectAchievementComponent is a prefab component used to configure object-based achievements for a prefab in Cities: Skylines 2. It exposes an array of achievement setups (serializable) that are converted into runtime ObjectAchievementData entries on the entity's dynamic buffer during initialization. The class is annotated with a ComponentMenu attribute so it can be added via the editor under the "Achievements/" menu.
Fields
-
public ObjectAchievementSetup[] m_Achievements
This array holds one or more ObjectAchievementSetup entries (defined below). Each entry describes an achievement associated with the prefab (achievement id and counter options). The array is serialized so it can be configured in the editor/inspector. -
Serializable nested struct ObjectAchievementSetup
public AchievementId m_ID
The identifier of the achievement to associate with this prefab instance.public bool m_BypassCounter
When true, indicates the achievement should bypass normal counting logic (implementation-specific).public bool m_AbsoluteCounter
When true, indicates the achievement should use absolute counting semantics (implementation-specific).
This struct is a simple container used to populate ObjectAchievementData entries at initialization time.
Properties
- None declared on this class.
All configuration is stored in fields and translated into entity components/buffers at Initialize time.
Constructors
public ObjectAchievementComponent()
Default constructor (implicit). No custom construction logic is defined in this class; initialization is performed in Initialize(EntityManager, Entity).
Methods
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds ComponentType.ReadWrite() to the provided set. This ensures the runtime archetype for entities with this prefab includes the ObjectAchievement component (used for instance-level achievement state). -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds ComponentType.ReadWrite() to the provided set. This declares that the prefab will carry a buffer of ObjectAchievementData entries (the data structure populated from m_Achievements). -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated to initialize ECS data. It: - Calls base.Initialize(entityManager, entity).
- Retrieves the DynamicBuffer
from the entity. - Iterates over m_Achievements and adds an ObjectAchievementData element per entry, copying m_ID, m_BypassCounter and m_AbsoluteCounter into each buffer element. This transfers the authoring-time configuration into runtime ECS buffer data consumed by achievement systems.
Usage Example
// Configure via inspector or code on the prefab:
public class MyBuildingPrefab : ObjectAchievementComponent
{
void Reset()
{
// Example assignment done in editor-time or via code:
m_Achievements = new ObjectAchievementSetup[]
{
new ObjectAchievementSetup
{
m_ID = AchievementId.SomeAchievement,
m_BypassCounter = false,
m_AbsoluteCounter = true
}
};
}
}
// At runtime, when the prefab is instantiated, Initialize(EntityManager, entity)
// will copy the m_Achievements into the entity's DynamicBuffer<ObjectAchievementData>
// so achievement systems can read and process them.