Skip to content

Game.Prefabs.PlaceableObject

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Component used by placeable object prefabs (e.g., static objects and marker objects). Exposes editable prefab fields for construction cost and XP reward, registers required ECS components (PlaceableObjectData and PlaceableInfoviewItem) for the prefab entity, and initializes the entity component data at spawn. If the placement flags do not already indicate shoreline/floating/hovering, it will mark the object as OnGround. The class is annotated with a ComponentMenu attribute restricting it to StaticObjectPrefab and MarkerObjectPrefab.


Fields

  • public uint m_ConstructionCost = 1000u
    Default construction cost that will be written into the prefab's PlaceableObjectData during initialization. Editable on the prefab; default value is 1000.

  • public int m_XPReward
    Experience reward value written into the prefab's PlaceableObjectData during initialization.

Properties

  • This type does not declare public properties.

Constructors

  • public PlaceableObject()
    No explicit constructor is declared in the source; the component uses the default parameterless constructor. Prefab values are normally set in the editor; runtime initialization of ECS component data happens in Initialize(...).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the ECS component types required by this prefab to the provided set:
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite() This informs the prefab/entity creation system which components should be present.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No additional archetype components are added by this implementation (method is empty).

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab entity is initialized. Implementation:

  • Calls base.Initialize(...)
  • Reads PlaceableObjectData from the entity
  • Writes m_ConstructionCost and m_XPReward into the PlaceableObjectData
  • Ensures placement flags: if none of PlacementFlags.Shoreline, PlacementFlags.Floating, or PlacementFlags.Hovering are set, it sets PlacementFlags.OnGround
  • Writes the updated PlaceableObjectData back to the entity via entityManager.SetComponentData(...)

Usage Example

// Example: subclassing or using the component during entity initialization
using Unity.Entities;
using UnityEngine;
using Game.Prefabs;

public class MyPlaceableObject : PlaceableObject
{
    public override void Initialize(EntityManager entityManager, Entity entity)
    {
        base.Initialize(entityManager, entity);

        // Read back the written component data
        var data = entityManager.GetComponentData<PlaceableObjectData>(entity);
        Debug.Log($"Construction cost: {data.m_ConstructionCost}, XP reward: {data.m_XPReward}");
    }
}

{{ Additional notes: - The ComponentMenu attribute on the class limits this component to specific prefab types (StaticObjectPrefab and MarkerObjectPrefab). - The PlacementFlags enum controls where and how an object can be placed; this component defaults objects to OnGround unless another placement category is explicitly set. - GetPrefabComponents is used by the prefab-to-entity conversion pipeline to ensure the entity has the correct component types; GetArchetypeComponents can be used to add components at archetype creation time but is unused here. }}