Skip to content

Game.Prefabs.AchievementFilter

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
Component attached to prefabs (typically BuildingPrefab) to mark which achievements the prefab is valid or not valid for. On initialization it writes entries into a DynamicBuffer on the prefab's entity recording allowed and disallowed AchievementId values. This is used by the achievements system to filter prefabs for achievement-related logic.


Fields

  • public AchievementId[] m_ValidFor
    Array of AchievementId values for which this prefab is explicitly allowed. When present, Initialize() will add AchievementFilterData entries with m_Allow = true for each ID.

  • public AchievementId[] m_NotValidFor
    Array of AchievementId values for which this prefab is explicitly disallowed. Initialize() will add AchievementFilterData entries with m_Allow = false for each ID.

Properties

  • None (this class does not declare properties)

Constructors

  • public AchievementFilter()
    Default parameterless constructor (compiler-provided). The component relies on Unity/inspector initialization of the public arrays; no constructor logic is required.

Methods

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    This override is intentionally empty in this implementation. In other components this method is used to declare which components belong to an entity archetype. Here it makes no additions.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component type required by this prefab: components.Add(ComponentType.ReadWrite()); This ensures the prefab's entity will have a DynamicBuffer available.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when setting up the prefab entity. Retrieves the DynamicBuffer for the entity and adds entries for each AchievementId in m_ValidFor (m_Allow = true) and m_NotValidFor (m_Allow = false). Both arrays are null-checked; if null, no entries are added for that list.

Notes: - AchievementFilterData is expected to be a buffer element struct with at least fields m_AchievementID and m_Allow. - This method uses entityManager.GetBuffer(entity) which requires that the component type was previously added in GetPrefabComponents.

Usage Example

// Placed on a prefab (e.g., BuildingPrefab) via inspector:
public class AchievementFilter : ComponentBase
{
    public AchievementId[] m_ValidFor;    // set in inspector
    public AchievementId[] m_NotValidFor; // set in inspector

    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        components.Add(ComponentType.ReadWrite<AchievementFilterData>());
    }

    public override void Initialize(EntityManager entityManager, Entity entity)
    {
        base.Initialize(entityManager, entity);
        var buffer = entityManager.GetBuffer<AchievementFilterData>(entity);
        if (m_ValidFor != null)
        {
            foreach (var id in m_ValidFor)
            {
                buffer.Add(new AchievementFilterData { m_AchievementID = id, m_Allow = true });
            }
        }
        if (m_NotValidFor != null)
        {
            foreach (var id in m_NotValidFor)
            {
                buffer.Add(new AchievementFilterData { m_AchievementID = id, m_Allow = false });
            }
        }
    }
}

Additional information: - Ensure AchievementFilterData is declared as a IBufferElementData-compatible struct and is recognized by the game's ECS pipeline. - This component is intended for prefab-time setup: avoid adding large arrays at runtime per-entity; prefer prefab-configured arrays in the editor.