Skip to content

Game.Prefabs.TaxableResource

Assembly: Assembly-CSharp (game code / modding assembly)
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
TaxableResource is a prefab component used to mark a resource prefab as taxable and to supply the tax-area configuration for that prefab. At entity initialization it writes a TaxableResourceData component (constructed from the configured TaxAreaType array) to the entity so systems that process taxation can read which tax areas apply to this resource prefab. The class is exposed in the editor via a ComponentMenu attribute and is intended to be added to resource prefabs.


Fields

  • public TaxAreaType[] m_TaxAreas
    Array of tax area types configured on the prefab. When non-null, these values are packaged into a TaxableResourceData and written to the entity during Initialize. This is typically set in the prefab/authoring stage (inspector or prefab creation script).

Properties

  • None

Constructors

  • public TaxableResource()
    Implicit default constructor. No custom construction logic is defined in the class.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Registers the runtime component type that this prefab will have. This implementation adds a read/write TaxableResourceData component type to the provided components set: components.Add(ComponentType.ReadWrite());

This ensures the prefab's entity will include the TaxableResourceData component so it can be populated at initialize time.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No archetype components are added by this class. The method is intentionally left empty.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is converted to an entity / when the entity is created. This implementation:

  • Calls base.Initialize(entityManager, entity)
  • If m_TaxAreas is not null, constructs a new TaxableResourceData(m_TaxAreas) and writes it to the entity with entityManager.SetComponentData(entity, ...)

This is the point where the authoring data (the m_TaxAreas array) is transferred into an ECS component for runtime use.

Notes: - The method guards against a null m_TaxAreas; if null, no TaxableResourceData is written. - It assumes the existence of a TaxableResourceData type that accepts the TaxAreaType[] in its constructor.

Usage Example

// Example: configuring the prefab (in editor or prefab creation code)
var taxable = prefabGameObject.AddComponent<TaxableResource>();
taxable.m_TaxAreas = new[] { TaxAreaType.Commercial, TaxAreaType.Industrial };

// At entity conversion / initialization the component system will call:
protected override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);
    // The TaxableResource will write:
    // entityManager.SetComponentData(entity, new TaxableResourceData(m_TaxAreas));
}

Additional implementation details and notes: - Attribute: [ComponentMenu("Resources/", new Type[] { typeof(ResourcePrefab) })] — exposes the component under the Resources menu for ResourcePrefab authoring. - Dependencies: Unity.Entities (Entity, EntityManager, ComponentType), TaxAreaType enum, TaxableResourceData struct/class, ResourcePrefab (for component menu grouping). - Typical use-case: used by taxation systems to determine which tax areas a spawned resource entity belongs to so tax calculations and collection logic can include the resource.