Skip to content

Game.Prefabs.PillarObject

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
PillarObject is a prefab component used for pillar-type objects (used by static and marker object prefabs). It exposes configuration for the pillar type, a per-prefab vertical offset range, and an optional placement anchor offset. At initialization it writes a PillarData component to the entity and — if an anchor offset is specified — adjusts the PlaceableObjectData placement offset on the entity.


Fields

  • public PillarType m_Type
    Specifies the pillar kind (enum). Written into the PillarData.m_Type when the prefab is initialized.

  • public float m_AnchorOffset
    A vertical placement anchor offset. If non-zero, the prefab adds a dependency on PlaceableObjectData and sets PlaceableObjectData.m_PlacementOffset.y to this value during initialization. Useful to raise/lower the visual anchor of the object.

  • public Bounds1 m_VerticalPillarOffsetRange = new Bounds1(-1f, 1f)
    Range used for the pillar's vertical offset. This value is copied into PillarData.m_OffsetRange so the runtime placement/job systems know the allowed vertical offset for this pillar prefab.

Properties

  • None declared on this type.

Constructors

  • public PillarObject()
    Default parameterless constructor (implicit). The class relies on serialized field values (m_Type, m_AnchorOffset, m_VerticalPillarOffsetRange) provided by the prefab asset.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component types required by this prefab:
  • Always adds PillarData (read/write).
  • Adds PlaceableObjectData (read/write) if m_AnchorOffset != 0f so initialization can apply the anchor offset.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds components that must be present on the entity archetype. For this prefab it adds the Pillar component (read/write), ensuring entities for this prefab are created with the Pillar component.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes the entity for this prefab:

  • Writes a PillarData struct constructed from m_Type and m_VerticalPillarOffsetRange to the entity via entityManager.SetComponentData.
  • If m_AnchorOffset != 0f, reads the existing PlaceableObjectData from the entity, sets its m_PlacementOffset.y to m_AnchorOffset, and writes it back. This ties the prefab's inspector-configured anchor offset into the entity's placeable data.

Additional notes: - The class is annotated with the ComponentMenu attribute and is available under the "Objects/" menu and intended to be used with StaticObjectPrefab and MarkerObjectPrefab. - Interacts with ECS through Unity.Entities.EntityManager and ComponentData APIs; care should be taken that the required components are included in the prefab archetype (GetPrefabComponents / GetArchetypeComponents).

Usage Example

// Example: behavior of PillarObject.Initialize (conceptual)
public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    // Create/assign PillarData from prefab fields
    PillarData pillar = default;
    pillar.m_Type = m_Type;
    pillar.m_OffsetRange = m_VerticalPillarOffsetRange;
    entityManager.SetComponentData(entity, pillar);

    // Apply optional anchor offset to the placeable data
    if (m_AnchorOffset != 0f)
    {
        var placeable = entityManager.GetComponentData<PlaceableObjectData>(entity);
        placeable.m_PlacementOffset.y = m_AnchorOffset;
        entityManager.SetComponentData(entity, placeable);
    }
}