Skip to content

Game.Prefabs.MapTilePrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: AreaPrefab

Summary:
MapTilePrefab is a prefab component used to configure and initialize ECS entity data for a map tile (area) in the game. It exposes purchase cost configuration and a list of feature-cost pairs (FeatureInfo) which are written into a MapFeatureData dynamic buffer on the entity during initialization. The class also registers required component types for the prefab and archetype so entities get the correct components (tile data, geometry and feature elements).


Fields

  • public float m_PurchaseCostFactor = 2500f
    This multiplier is stored into the entity as a TilePurchaseCostFactor component during Initialize. It represents the base purchase cost factor for this tile.

  • public FeatureInfo[] m_MapFeatures
    Array of FeatureInfo entries describing which MapFeature indices have custom costs. During Initialize these entries are written into the MapFeatureData dynamic buffer (indexed by the MapFeature enum value).

  • public class FeatureInfo

  • public MapFeature m_MapFeature
    The MapFeature enum value (index) this entry configures.
  • public float m_Cost
    The purchase cost (or cost factor) associated with the specified MapFeature. Each FeatureInfo creates a MapFeatureData with this cost that is stored in the MapFeatureData buffer.

Properties

  • None (no public properties are declared on this class).

Constructors

  • public MapTilePrefab()
    Default parameterless constructor (inherited behavior). No special initialization beyond field default values.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds component types required for the prefab instance to the provided set. Implementation adds:
  • MapTileData (ReadWrite)
  • MapFeatureData (ReadWrite)
  • AreaGeometryData (ReadWrite)
  • TilePurchaseCostFactor (ReadWrite)

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types required for the archetype (entity layout) to the provided set. Implementation adds:

  • MapTile (ReadWrite)
  • MapFeatureElement (ReadWrite)
  • Geometry (ReadWrite)

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes the given entity with prefab data:

  • Calls base.Initialize(entityManager, entity).
  • Retrieves the DynamicBuffer for the entity and ensures it has length 9 via CollectionUtils.ResizeInitialized(buffer, 9). (This reserves slots for map feature indices used by the game.)
  • Iterates m_MapFeatures and assigns buffer[(int)featureInfo.m_MapFeature] = new MapFeatureData(featureInfo.m_Cost) for each entry, writing the configured costs into the buffer at the MapFeature index.
  • Writes a TilePurchaseCostFactor component to the entity with value m_PurchaseCostFactor.

Usage Example

// Example: configure a MapTilePrefab on a GameObject (e.g. in the editor or setup script)
var prefab = gameObject.AddComponent<MapTilePrefab>();
prefab.m_PurchaseCostFactor = 3000f;
prefab.m_MapFeatures = new MapTilePrefab.FeatureInfo[]
{
    new MapTilePrefab.FeatureInfo { m_MapFeature = MapFeature.Forest, m_Cost = 0f },
    new MapTilePrefab.FeatureInfo { m_MapFeature = MapFeature.Mountain, m_Cost = 500f }
};

// When the ECS entity is created for this prefab, Initialize(EntityManager, entity) will
// populate the MapFeatureData buffer and set the TilePurchaseCostFactor component.