Skip to content

Game.Prefabs.PlaceableNetPiece

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
PlaceableNetPiece is a ComponentBase used for net (road/rail/etc.) prefabs. It exposes editable cost fields (construction, elevation and upkeep) and ensures those values are written into the ECS component PlaceableNetPieceData when the prefab is initialized. The class also carries a ComponentMenu attribute placing it under "Net/" in the editor prefab component menu.


Fields

  • public uint m_ConstructionCost
    Holds the construction cost for this net piece (unsigned integer). This value is transferred into the ECS PlaceableNetPieceData during Initialize.

  • public uint m_ElevationCost
    Holds the elevation (height change) cost for this net piece. Also copied to the ECS component in Initialize.

  • public float m_UpkeepCost
    Holds the recurring upkeep cost (float) for this net piece. Copied to PlaceableNetPieceData during initialization.

Properties

  • This class does not declare any C# properties. It exposes public fields instead.

Constructors

  • public PlaceableNetPiece()
    The default parameterless constructor is used by Unity when the component is created. No custom construction logic is defined in the class.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the ECS component type required by this prefab to the provided set. Specifically, it calls: components.Add(ComponentType.ReadWrite()); This signals that entities created from this prefab need a read/write PlaceableNetPieceData component.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty override. The method is present but does not add any archetype components in this implementation.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is converted/initialized into an ECS entity. It invokes base.Initialize and then sets the PlaceableNetPieceData component on the given entity using the component's public fields:

  • m_ConstructionCost -> PlaceableNetPieceData.m_ConstructionCost
  • m_ElevationCost -> PlaceableNetPieceData.m_ElevationCost
  • m_UpkeepCost -> PlaceableNetPieceData.m_UpkeepCost

Usage Example

// Example: when a prefab is initialized, the engine will call Initialize.
// The following demonstrates the same logic that happens inside Initialize.
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Suppose entityManager and entity are provided by conversion pipeline:
    var placeable = gameObject.GetComponent<PlaceableNetPiece>();
    entityManager.SetComponentData(entity, new PlaceableNetPieceData
    {
        m_ConstructionCost = placeable.m_ConstructionCost,
        m_ElevationCost = placeable.m_ElevationCost,
        m_UpkeepCost = placeable.m_UpkeepCost
    });
}

Notes and tips: - PlaceableNetPieceData must be defined elsewhere in the project; this component writes data into that ECS struct. - Because the class uses public fields (rather than properties), values are editable in the Unity inspector on the prefab. - The ComponentMenu attribute ("Net/") determines where this component appears in the prefab component menu for easy assignment to net prefabs.